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

Discussion in 'C++' started by Christof Krueger, Dec 19, 2003.

  1. 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;

    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
    CBoard::copy(CBoard &other)
    for (map<string,CNode*>::iterator i = nodes.begin();
    i != nodes.end();
    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
    Christof Krueger, Dec 19, 2003
    1. Advertisements

  2. Ouch!!!

    I should have used the new operator...

    that really hurts! :-/
    Christof Krueger, Dec 19, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.