d04 ex02 change pour pouvoir effectuer le test de erlazo
This commit is contained in:
38
d04/ex02/test_assignement.cpp
Normal file
38
d04/ex02/test_assignement.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
# 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user