copy con & assign oper. in derived objects
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?
well, i found out that copy constructors work ok, but assignment operators dont, unless i do this:
is this ok?
[edited by - vesoljc on January 25, 2004 7:57:45 AM]
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]
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){}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement