This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Why aren't assignment operators inherited automatically?
- From: Topi Maenpaa <topiolli at ee dot oulu dot fi>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 16 Mar 2005 10:45:16 +0200
- Subject: Why aren't assignment operators inherited automatically?
- Organization: University of Oulu
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-