Inheritance and Polymorphism Forwarding Declartion (spiffy title, no?)

Started by
1 comment, last by deadimp 19 years, 3 months ago
The title explains it all. I am having trouble with a forward declaration of a child class that is part of a polymorphic pointer. Example: (class 'instance' is the parent')
[source lang='cpp']
instance *object[ 1000 ]; //Just an example
//I try using it in a template and typeid operation.
 template <typename objType>
bool something() {
 if (typeid(objType)==typeid(*object[id])) //Yadayada
}
...
class CTest;
...
//In a function elsewhere in a different class
 something<CTest>();
...
class CTest : public instance {
 ...
};

This isn't the exact scenario, but I get a slew of errors. Now, what should I do? Should I just declare an example object like 'CTest objTest;' and have it as an argument in the function (with a template)? And yes, I do check if the object actually exists. (This isn't too clear, so I apologize)
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Advertisement
You are attempting to use type data of a type which isn't defined (only declared). A declaration isn't enough to use typeid, which requires a complete type. Since CTest is only declared and not defined, when "something" is instantiated with the CTest type, the typeid expression is invalid. You have to have CTest's definition appear somewhere in your code. A declaration isn't enough information for a typeid expression to be performed.

Edit: If you are defining CTest and it is a runtime error, make sure you have runtime type information enabled on your compiler (it is often disabled by default, though you should get a warning about it if you attempt to compile using typeid with it disabled).

[Edited by - Polymorphic OOP on January 15, 2005 11:15:01 PM]
Yeah, I guessed that with this system I'm going to be using, it's going to be somewhat screwy... Time for Plan B.
Thanks.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire

This topic is closed to new replies.

Advertisement