This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Why aren't assignment operators inherited automatically?


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-


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]