473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

operator inheritance from a class template???

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::operator=(const vec_d&)

Any ideas, please???
jose,

Jul 22 '05 #1
2 1285
jmborr wrote:

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::operator=(const vec_d&)


When in doubt, simplify. The problem has nothing to do with templates.
Read about assignment operators and inheritance.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #2
jmborr wrote:
Hi all,
For some reason, my derived class does not inherit the operator '='
of my base class,
The reason is that operator= is never inherited.
which is a class template, when I compile with g++
//=========== base class template<class T>
class vec{
public:
vec &operator=( vec ) ;
With the above signature, the right hand vec will be copied into the
parameter before it then is copied into the this object. So you shuold
probably use a (const) reference:

vec& operator=(const vec&);
};
//=========== derived class
class vec_d : vec<double> {
};
//===========
Why don't you just typedef it?

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

Any ideas, please???
jose,


--
First they ignore you. Then they laugh about you.
Then they fight you. And then you win.
(Mahatma Gandhi)

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
3
by: W. Cerven | last post by:
I am using the C++ STL container "list" to create a template nested list. Attached are my basic code and compiler errors. Oddly enough, I when I create a non-template version of this nested list,...
7
by: Mikhail N. Kupchik | last post by:
Hi All. I have a question regarding Herb Sutter's idiom of implementation of operator= via nonthrowing swap() member function, to guarantee strict exception safety. The idea of the idiom is...
3
by: danilo.horta | last post by:
Hi folks I'm having a scope resolution issue. The gnu compiler is trying to use the "operator function" from derived class rather than from correct one, the base class. // VecBasis.h file...
34
by: Chris | last post by:
Is there ever a reason to declare this as if(*this == rhs) as opposed to what I normally see if(this == &rhs) ?
11
by: Zilla | last post by:
I have the following simple program. I just want to be able to do math operations (+, -, =)on Timer sublcasses, but want to handle cases where either rhs or lhs is an intrinsic value, However, the...
2
by: Joachim | last post by:
Hello, I have been trying to get the following code to work, but unfortunately without any succes so far. I have searched in newsgroups and google but found nothing there that could solve my...
9
by: wo3kie | last post by:
#include <iostream> #include <map> #include <utility> // // Base // / | \ // Derived1 Derived2 \ // \ | / // Derived3
2
by: Peng Yu | last post by:
Hi, In the following code, the 'copy' member function works. But the '=' operator does not work. Can somebody let me know why a member function is different from an operator. Thanks, Peng ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.