Jump to content
  • Advertisement

Archived

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

Whirlwind

Simple C++ Question About Inheritance

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

If I declare parent object as part of a child object variable list, can I simply assign any child object to the parent object? Example: class parentobject { public: some variables; somefunctions(); } class childobject1:parentobject { public: parentobject thingie; etc... } class childobject2:parentobject { blah blah blah } . . . // main code childobject1 child1; childobject2 child2; child1.thingie=child2; Honest, I''m trying.

Share this post


Link to post
Share on other sites
Advertisement
Actually:

child1.thingie = child2;

Won''t work unless you either:

a) make child1.thingie a pointer or a reference.
b) overload operator= to assign a childobject2 to a parentobject.

Mason McCuskey
Spin Studios - home of Quaternion, 2000 GDC Indie Games Fest Finalist!
www.spin-studios.com

Share this post


Link to post
Share on other sites
Oh yeah, forgot about that ''public, private, friend, protected'' for inheritance.

I kind of thought that simply assigning a object to it''s parent was too simple. It probably will be a pointer in a linked list by the time it is all said and done with.

Thanks a lot, all. It has been a year since I''ve had a go at C++, C worked fine form my <100 line utility coding I was doing. Time break out the cliff notes .

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!