Có mã này:Chuyển nhượng nhà điều hành thừa kế
#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;
}
Kết quả sau khi biên dịch bằng g ++ 4.6:
Constructor base
Constructor base
Assignment base
Destructor base
Destructor base
Tại sao nhiệm vụ điều hành của lớp cơ sở được gọi là altough người ta nói rằng toán tử gán không phải là thừa hưởng?
có thể trùng lặp của [Trouble with inheritance of operator = in C++] (http://stackoverflow.com/questions/3882186/trouble-with-inheritance-of-operator-in-c) –