Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

iGore

Class pointers?

This topic is 5921 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

This is probably a simple question to answer but I''m curious. In C++, can you have a pointer to an instance of any class? Like you have two separate classes and want a pointer to be able to point to either one of the two. do you declare it as a (void*)or what? -iGore Productions-

Share this post


Link to post
Share on other sites
Advertisement
The only way to do exactly what you want is through a void pointer, yes. However, you can have a base class that a set of classes are derived from, and then use a pointer to the base class type to point to any of the derived types.

Share this post


Link to post
Share on other sites
Or, if you designing the classes yourself then the clean way to this is to create a new class that both your classes inherit from. That way you are sure that the pointer can be used for only those classes and not everything else.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!