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;
}
이 compilaton에 오류 준다 : B :: 연산자 = (A &)는 비표준 서명을 가지기 때문에할당 연산자
은, 컴파일러가 자신 B의 생성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
:: operator = (B &) A :: operator (A &)를 호출하려고 시도합니다 (A &).
B 인수에도 B :: operator = (A &)를 사용할 수있는 컴파일러가 있습니까?
내가 너무 기본 클래스의 저자입니다. 내가하고 싶은 것은 불변의 기본 클래스를 가지고 파생 된 클래스에 "돌연변이"함수를 추가하는 것입니다. 연산자 =()의 rhs 만 읽히므로 인수를 기본 클래스에 대한 참조로 만드는 것이 좋습니다. – Pibben