class A {
private:
A& operator=(const A&);
};
class B : public A {
public:
B& operator=(const A&) {
return *this;
}
};
int main() {
B b1;
B b2;
b1 = b2;
return 0;
}
Это дает ошибку при компиляции:
test.cpp: In member function 'B& B::operator=(const B&)':
test.cpp:16:5: error: 'A& A::operator=(const A&)' is private
test.cpp:19:20: error: within this context
test.cpp: In function 'int main()':
test.cpp:31:7: note: synthesized method 'B& B::operator=(const B&)'
first required here
Build error occurred, build is stopped
Поскольку B :: operator = (A &) имеет нестандартную сигнатуру, компилятор генерирует свой собственный B :: operator = (B &)который (пытается) вызвать A :: operator (A &), который является приватным.
Есть ли способ заставить компилятор использовать B :: operator = (A &) также для аргументов B?