Original Post
I'm currently experimenting with building some re-usable C++ lib's that will give me some simple things like Math and Container classes. Thus far the effort has been going well, but I've hit a pretty dang big snag... I've got a RTTI (Run Time Type Identification) system in place that I'm implementing into all of my classes to allow me to, well, identify them at run time. The RTTI system itself is heavily inspired by the system in "3D Game Engine Architecture" by David Eberly, with a few minor implementation specific changes, but nothing that should be system breaking. In any case, the main chunk of code looks like this: The class itself is commonly initialized as a static member variable, and initalized as such. So here's the issue - If I am compiling this code into an EXE and then running through and debugging everything looks great. the string copies correctly, hte parent type is correctly assigned, and all is right with the world. IF, however, I compile that same code into a LIB and then link to it in a seperate EXE (even if its the same code as the non-linked compile) strange things start happening... For one, an object type that shows up as "CTest" in the non-linked version is shown to be "CTestýýýý««««««««îþîþîþ" when linking to the lib. Also, the base types do not seem to be assigned correctly in the linked version, often coming up as NULL. (This last symptom seems more common on the templated container classes, though, so that may have something to do with it.) Now to try and pre-emptively answer a few questions: -All builds, linked and otherwise, are being preformed in debug mode, no optimizations, under VC++ 2005 Express. (And yes, I'm compiling the LIB in debug mode too.) -The problem with the names seems to occur wether the RTTI object is created statically or Dynamically. The NULL parent issue seems to occur mostly in templated classes, but both happen only when linking to the RTTI class through a static lib. -I have tried assigning strlen(name) to a variable (int len) to see what we get. In the non-linked version this comes out to the length of the string, as expected. In the linked version this comes out to -858993460, which effectively means it's not being set at all. As stated, this is somewhat of my first forray into compiling my own libs, so I could be doing something entirely wrong here, but aside from this facet of things I consider myself to be a pretty competent programmer (enough to score myself a job as one.) So I'm reasonably sure I'm not doing anything dumb in the code logic itself. If anyone has any suggestions here, I'd love to hear them! Thank you! [Edited by - Toji on April 16, 2006 9:10:32 AM]
class CRTTI{
...
private:
char* typeName;
const CRTTI* typeBase;
};
CRTTI::CRTTI( const char* name, const CRTTI* baseType ) {
typeName = new char[strlen(name)+1];
typeName[strlen(name)] = '\0';
memcpy(typeName, name, (strlen(name)) * sizeof(char));
typeBase = baseType;
}