I have an assignment that demands I use a copy constructor. So let's say we have the following code:
class Animal /*abstract class*/
{
private:
string name;
int age;
public:
Animal();
~Animal();
virtual int is_bad() = 0;
}
class Dog : public Animal
{
public:
Dog();
~Dog();
int is_bad() {
return 0;
}
}
/*constructors*/
Animal::Animal(int age,string name)
{
this->age=age;
this->name=name;
}
Dog::Dog(int age, string name) : Animal(age,name)
{
cout << "Woof" << endl;
}
/*main*/
int main()
{
Animal * c;
c = new Dog(10,"rex");
return 0;
}
So my question is as follows. If I want to make a copy constructor that makes a duplicate of dog for example Dog(const Dog & d)
, what do I need to add to my code and how do I call it in my main function?
I'm a newbie so I'll need a quite elaborated answer.