why, if we have a pure virtual assignment operator in the base class, then we implement this operator in the derived class, it gives a linker error in the base class?
Currently, I only have the following explanation http://support.microsoft.com/kb/130486 , he said that the behavior is by design, since normal inheritance rules do not apply .
I don’t understand why it generates a design linker error? can someone give me a clearer explanation on this?
edit: added my simplified code from which the error occurred:
class __declspec(dllexport) BaseClass {
public:
int memberA;
virtual BaseClass& operator=(const BaseClass& rhs) = 0;
};
class __declspec(dllexport) DerivedClass : public BaseClass {
public:
int memberB;
DerivedClass():memberB(0) {}
virtual BaseClass& operator=(const BaseClass& rhs) {
this->memberA = rhs.memberA;
this->memberB = 1;
return *this;
}
};
int main(void)
{
DerivedClass d1;
DerivedClass d2;
BaseClass* bd1 = &d1;
BaseClass* bd2 = &d2;
*bd1 = *bd2;
}
__declspec(dllexport) / = .
__declspec(dllexport) *bd1 = *bd2;, d1:: memberB 1, __declspec(dllexport) d1:: memberB
__declspec(dllexport) *bd1 = *bd2;, d1:: memberB