Re: operator= inherited from template
On May 26, 1:24 pm, Daniel Kraft <d...@domob.eu> wrote:
understanding of C++, it should be inhertied like a simple function?
operator= is a very special member function in two ways:
1.It can not be defined as a binary static/none-member operator
wheras other operators (say operator+(left,right)) can.
2.It is not inherited.
the general inheritance behavior of this operator resembles the copy-
constructor:
1.if A class 'C1' hides its operator=(C1) then inherited classes and
classes that have a data member of 'C1' type can not automatically
generate an operator= .
2.it is overloadable with other parameters but not inheritable;the
inherited class must define its own operator= -in case the operand to
that of base is not of the self type- which calls the base:
class base{
public:
base& operator=(int);//not inherited
//private://if uncommented derived will not be assignable
base& operator=(base&);
};
class derived:public base{};
derived d1, d2;
d1=d2;/*as long as base::operator=(base&) is public it is ok,otherwise
error*/
d1=1;//error: base& base::operator=(int) not inheritable.
The program works as expected when I either replace abc=5; with the line
just as expected.
Are operators handled differently from ordinary functions when
not the others.
inheriting or maybe when inheriting from templates?
***No.***