There is this code:
#include <iostream>
class Base {
public:
Base(){
std::cout << "Constructor base" << std::endl;
}
~Base(){
std::cout << "Destructor base" << std::endl;
}
Base& operator=(const Base& a){
std::cout << "Assignment base" << std::endl;
}
};
class Derived : public Base{
public:
};
int main ( int argc, char **argv ) {
Derived p;
Derived p2;
p2 = p;
return 0;
}
The output after compilation by g++ 4.6:
Constructor base
Constructor base
Assignment base
Destructor base
Destructor base
Why assignment operator of base class is called altough it is said that assignment operator is not inherited?
See Question&Answers more detail:os