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

This topic is 4719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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() {
}
...
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)

Share on other sites
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]

Share on other sites
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.

Share on other sites

This topic is 4719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628754
• Total Posts
2984514

• 12
• 25
• 12
• 10
• 17