copy con & assign oper. in derived objects

Started by
2 comments, last by vesoljc 20 years, 2 months ago
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?
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
Advertisement
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){     base_class::operator=(ldRhs);     // transfer data from this class     return(*this);}


is this ok?

[edited by - vesoljc on January 25, 2004 7:57:45 AM]
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
Thats fine. You would call the copy constructor of the base class using an initialization list

derived_class::derived_class(const derived_class& der):base_class(der){}
tnx
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com

This topic is closed to new replies.

Advertisement