I'm having a bit of trouble finding the info I need about copy constructors. Actually, I'm having a bit of trouble figuring out the right way to use them in the first place.
My question: How do I correctly call copy constructors for a derived class so that it correctly copies data from the base class as well? Here's what I've come up with.
class Base
{
Base();
Base(const Base &theObject);
int baseData;
int GetData1() const {return baseData;}
};
Base::Base(const Base &theObject)
{
baseData = theObject.GetData1() ;
}
class Derived : public Base
{
Derived();
Derived(const Derived &theObject);
int derivedData;
int GetData2() const {return baseData;}
}
Derived:: Derived( const Derived &theObject)
{
Base( &theObject );
derivedData = theObject.GetData2();
}
Is this what a copy constructor is supposed to do?