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, 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)
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) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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,...
|
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...
|
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...
|
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)
?
|
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...
|
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...
|
by: wo3kie |
last post by:
#include <iostream>
#include <map>
#include <utility>
//
// Base
// / | \
// Derived1 Derived2 \
// \ | /
// Derived3
|
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
...
|
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,...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
| |