I have a map in a class and when I compile I get an error in the
overloaded assignment operator but not in the copy constructor:
typedef std::map<wxString, const void*> MethodMap;
MethodMap mMethods;
MethodMap hePlugin::GetAllMethods(){return mMethods;}
// This works...
hePlugin::hePlugin(const hePlugin& plugin) : mMethods(plugin.GetAllMethods()){
}
// This doesn't...
const hePlugin hePlugin::operator = (const hePlugin& plugin){
mMethods(plugin.GetAllMethods()); <== error
return *this;
}
The error I get when compiling (gcc 3.2.2 on RedHat 9) is:
no match for call to `(MethodMap) (MethodMap)`
Thanks in advance for any help!
--
Benny
(Remove your_rose_colored_glasses to mail me) 2 5355
Benny Hill wrote: I have a map in a class and when I compile I get an error in the overloaded assignment operator but not in the copy constructor:
typedef std::map<wxString, const void*> MethodMap; MethodMap mMethods; MethodMap hePlugin::GetAllMethods(){return mMethods;}
In this code you are using the copy constructor for MethodMap // This works... hePlugin::hePlugin(const hePlugin& plugin) : mMethods(plugin.GetAllMethods()){ }
Here you are trying to use a constructor in an already contructed varible // This doesn't... const hePlugin hePlugin::operator = (const hePlugin& plugin){ mMethods(plugin.GetAllMethods()); <== error return *this; }
In order to copy stl elements, do something in the lines of:
//
mMethods.assign(plugin.GetAllMethods().begin(),plu gin.GetAllMethods().end()),
//
or if it really works for you, just do
//
mMethods = plugin.GetAllMethods();
//
By the way, if you want to make your GetAllMethods function to be a
little more efficient, return const& MethodMap instead of a copy...
Benny Hill wrote: I have a map in a class and when I compile I get an error in the overloaded assignment operator but not in the copy constructor:
typedef std::map<wxString, const void*> MethodMap; MethodMap mMethods; MethodMap hePlugin::GetAllMethods(){return mMethods;}
Do you really want to return a copy of the map here? Maybe a const& is
enough...
And make the method const!
// This works... hePlugin::hePlugin(const hePlugin& plugin) : mMethods(plugin.GetAllMethods()){ }
// This doesn't... const hePlugin hePlugin::operator = (const hePlugin& plugin){ mMethods(plugin.GetAllMethods()); <== error
Try this:
mMethods = plugin.GetAllMethods();
hth
Christoph This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Antti Granqvist |
last post by:
Hello!
I have following object relations:
Competition 1--* Category 1--* Course
1
|
|
*
Course
|
by: Flzw |
last post by:
Well I have a map like this :
std::map <string, CObject> ObjectList;
I have a function like this :
CObject* NewObject( char* Name, CArg* Arg)
{
std::string key = Name;
ObjectList =...
|
by: Bob |
last post by:
Hi,
I'm trying to use a map with a string key, and a pointer to objects
contained in a vector. I've wrapped this in a class like so:
// cMap
template<class T> class cMap : public cList<T> { ...
|
by: jstanforth |
last post by:
This is probably a very obvious question, but I'm not clear on what
operators need to be implemented for std::map.find() to work. For
example, I have a class MyString that wraps std::string, and...
|
by: Erik Wikström |
last post by:
First of all, forgive me if this is the wrong place to ask this question,
if it's a stupid question (it's my second week with C++), or if this is
answered some place else (I've searched but not...
|
by: Dan Trowbridge |
last post by:
Hi everyone,
In my attempt to port code from VS 6.0 to VS.NET I had some code break along
the way, mostly due to not adhereing closely to the C++ standard. This may
be another instance but I...
|
by: Matthias Pfeifer |
last post by:
Hi there,
a std::map is build from std::pair elements where for a pair p p.first
is called the key and p.second the value. Is there a way to keep the map
sorted by the values? Ie is there a...
|
by: Chris Forone |
last post by:
Hello group,
g++ (3.4.2, mingw):
float init = {1.f, 2.f, 3.f};
std::map<std::string, std::valarray<float mp;
mp = std::valarray(init, 3);
mp.size(); // should be 3, but IS 0!
|
by: Juha Nieminen |
last post by:
joseph cook wrote:
Not always. By default, yes, but you can specify other comparators, eg:
std::map<int, int, std::greaterreversedMap;
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |