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;
    ...
    };
    --------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
    Christof Krueger, Dec 19, 2003
    #1
    1. Advertising

  2. Christof Krueger wrote:

    > nodes[i->first] = CNode(*(i->second));


    Ouch!!!

    I should have used the new operator...

    that really hurts! :-/
    Christof Krueger, Dec 19, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nans
    Replies:
    2
    Views:
    20,096
    Martin Marinov
    Jun 17, 2004
  2. nagy
    Replies:
    36
    Views:
    1,007
    Terry Reedy
    Jul 20, 2006
  3. Donald Gillies
    Replies:
    3
    Views:
    328
    Dave Rahardja
    Oct 4, 2005
  4. Angus
    Replies:
    2
    Views:
    1,494
    Ron Natalie
    Jan 7, 2007
  5. juglesh
    Replies:
    5
    Views:
    209
    Thomas 'PointedEars' Lahn
    May 15, 2005
Loading...

Share This Page