By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

cannot convert `xyz' to `xyz*' in assignment

P: n/a
Hello,

I get a compilation error with the following code but I do not
understand why this happens. Maybe somebody can explain, what the
compiler (GCC ) tries to do and why it fails.

-------[ CBoard.h ]--------
class CBoard {
...
map<string,CNode*> nodes;
...
};
--------8<-----------------

copy is called in the copy constructor and in the assignment operator.
It has to copy key=>value pairs from one map to another. CNode provides
a copy constructor, of course:

------[ CBoard.cpp ]-------
#include "CBoard.h"
....
// copy object
void
CBoard::copy(CBoard &other)
{
for (map<string,CNode*>::iterator i = nodes.begin();
i != nodes.end();
i++)
{
nodes[i->first] = CNode(*(i->second));
}
}
....

----[ compiler output ]----

CBoard.cpp: In member function `void CBoard::copy(CBoard&)':
CBoard.cpp:79: cannot convert `CNode' to `CNode*' in assignment
make: *** [board.o] Error 1

---------------------------

Regards,
Christof

Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Christof Krueger wrote:
nodes[i->first] = CNode(*(i->second));


Ouch!!!

I should have used the new operator...

that really hurts! :-/

Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.