When would you need to use a copy constructor
Hello,
I am doing some reading on copy constructors. I know that the compiler will create a default copy constructor.
But what is the real reason that people use copy constructors? This is the code I have been working with. I understand the coding ok.
Code:
class Mammal
{
public:
Mammal():itsAge(1) { cout << “Mammal constructor...\n”; }
virtual ~Mammal() { cout << “Mammal destructor...\n”; }
Mammal (const Mammal & rhs);
virtual void Speak() const { cout << “Mammal speak!\n”; }
virtual Mammal* Clone() { return new Mammal(*this); }
int GetAge()const { return itsAge; }
protected:
int itsAge;
};
Many thanks,