Jump to content
  • Advertisement


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


copy con & assign oper. in derived objects

This topic is 5412 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 my base class has custom copy constructor and custom assignment operator and my derived class also, do i have to manually call the base class const and operator? coz, i tried this: my base class serves as an ID class, it has an ID string and few functions for ID access. allthough compiler generated copy constructor and assignemnt oper would work, i intetionaly added them for debugging and learning i then create a new class, derive from ID class and again add copy con and assign oper... i then create two classes, give them diffrent id and try to assign one to another. new class data gets transfered ok, but id''s dont change... so i''m guessing that i have to call them manually?

Share this post

Link to post
Share on other sites
well, i found out that copy constructors work ok, but assignment operators dont, unless i do this:

const derived_class& derived_class::operator=(const derived_class& ldRhs)
// transfer data from this class


is this ok?

[edited by - vesoljc on January 25, 2004 7:57:45 AM]

Share this post

Link to post
Share on other sites
Thats fine. You would call the copy constructor of the base class using an initialization list

derived_class::derived_class(const derived_class& der)

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!