Jump to content
  • Advertisement


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


Upcasting and downcasting class pointers.

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

Hey all. I''ve been going through a C++ for a while now, and I''m at the point where I''m very confident with most constructs of the language. However, to make absolutely certain of this, I''ve been coding lots of little "meaningless" programs; it seems to be doing the trick. Now, I''ve just come across upcasting and downcasting of class pointers in the book I''m going through. So, again, I thought I''d try my own example (just to see if I know when to use this sort of theory). I''ve come up with the following test scenario: 1.) Make a class called Garage, which should be used to store MAXSPACES vehicles. 2.) Have a generic Vehicle class, of which several derived classes can be made; classes Car and Bike, just to keep it simple. 3.) Have an array of pointers to type Vehicle in class Garage; these would be dynamically allocated to Vehicles classes by the Garage constructor. The idea was to produce this set of classes, and fiddle around with up and downcasting pointers (being as Vehicle is a generic type, and I wouldn''t know the vehicles that would be stored in Garage until run-time). Am I on the right lines with this, or can someone think of a better scenario to have a bash at? Thanks. --hellz

Share this post

Link to post
Share on other sites
Nice idea, and it ties in with sort of what I was saying (although your scenario attacks it more head on).

I''ll have a go at that mate, thanks.


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!