Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

operator inheritance from a class template???

Status
Not open for further replies.

jmborr

Instructor
Feb 16, 2004
7
US
Hi all,
For some reason, my derived class does not inherit the operator '=' of my base class, which is a class template, when I compile with g++
//=========== base class
template<class T>
class vec{
public:
vec &operator=( vec ) ;
};
//=========== derived class
class vec_d : vec<double> {
};
//===========

When I compile, I have the following error:
no match for `vec_d& = vec<double>' operator
candidates are: vec_d& vec_d::eek:perator=(const vec_d&)

Any ideas, please???
jose,
 
Strictly speaking, it's doubtful what is the better:
Code:
vec_d x, y;
...
x = y; // your vec& =(vec) or implicit vec&=(const vec&)?
Keep it simple, simply redefine a normal assignment:
Code:
&vec operator=(const vec&)
 
opeartor = is not inherited

Ion Filipski
1c.bmp
 
operator= is, but not all uses of the operator call the operator= function... If it's a new object, it's the coy constructor


Code:
vec_d x = somevar; //copy constructor
...
Code:
vec_d x;
x = somevar; //operator=


redefinition is the better solution (and you can wrap a call to the parent's operator= if need be).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top