Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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

Share this post


Link to post
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 this post


Link to post
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.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this