39 lines
633 B
C++
39 lines
633 B
C++
# include <iostream>
|
|
# include <string>
|
|
|
|
class Animal {
|
|
public:
|
|
virtual Animal & operator=( Animal const & rhs ) {
|
|
std::cout << "Animal operator=\n";
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
class Cat : public Animal {
|
|
public:
|
|
Cat & operator=( Cat const & rhs ) {
|
|
Animal::operator=(rhs);
|
|
std::cout << "Cat operator=\n";
|
|
return *this;
|
|
}
|
|
Cat & operator=( Animal const & rhs ) {
|
|
Animal::operator=(rhs);
|
|
std::cout << "Cat operator=\n";
|
|
return *this;
|
|
}
|
|
void catSpeak() {std::cout << "I am a cat\n";}
|
|
};
|
|
|
|
int main() {
|
|
Animal* i = new Cat();
|
|
Animal* j = new Cat();
|
|
|
|
i->catSpeak();
|
|
j->catSpeak();
|
|
*i = *j;
|
|
|
|
delete i;
|
|
delete j;
|
|
}
|
|
|