40 lines
655 B
C++
40 lines
655 B
C++
#include <iostream>
|
|
|
|
class Base {
|
|
public:
|
|
Base () : _n(1) {}
|
|
Base & operator=(Base const & rhs) {
|
|
_n = rhs.getN();
|
|
std::cout << "base assignation operator\n";
|
|
return *this;
|
|
}
|
|
int getN() const {
|
|
return _n;
|
|
}
|
|
void putN(int i) {
|
|
_n = i;
|
|
}
|
|
protected:
|
|
int _n;
|
|
};
|
|
|
|
class Derived : public Base {
|
|
public:
|
|
Derived & operator=(Derived const & rhs) {
|
|
Base::operator=(rhs);
|
|
std::cout << "derived assignation operator\n";
|
|
return *this;}
|
|
};
|
|
|
|
int main () {
|
|
|
|
Derived foo1;
|
|
Derived foo2;
|
|
foo2.putN(2);
|
|
std::cout << foo1.getN() << " " << foo2.getN() << "\n";
|
|
foo2 = foo1;
|
|
std::cout << foo1.getN() << " " << foo2.getN() << "\n";
|
|
|
|
return 0;
|
|
}
|