Why aren't assignment operators inherited automatically?
Topi Maenpaa
topiolli@ee.oulu.fi
Wed Mar 16 10:43:00 GMT 2005
The question can be shortly formulated in C++ code as follows:
//Our fancy base class
class A
{
public:
//three (ought to be) equivalent functions with different names
A& operator= (int value) { return *this; }
A& operator*= (int value) { return *this; }
A& test(int value) { return* this; }
};
//The derived one
class B : public A
{
public:
//This is the weird thing here... Why do I need it?
using A::operator=;
};
int main()
{
A a; //create a
a = 1; //set to one, works fine
B b; //create b
A& a2 = b; //... and a reference to it
b = 1; //this fails without "using A::operator="
a2 = 1; //this works
b *= 1; //this also works
b.test(1); //and this
//so, what's the difference?
}
In short, anything inherited from the base class can be used as expected,
except the assignment operator. What's the deal? I'm doing this on Mandrake
10.1, gcc 3.4.1, if that matters.
Any hints are appreciated. Please cc to me, I'm not a subscriber.
-Topi-
More information about the Gcc
mailing list