Node operator=(Node node1,Node node2)
{
node1.Task=node2.Task;
node1.Place=node2.Place;
node1.Thing=node2.Thing;
node1.Description=node2.Description;
node1.Others=node2.Others;
node1.Time=node2.Time;
node1.TimeFlag=node2.TimeFlag;
return node1;
}这个函数为何在vc下通不过?
编译器提示只能有一个操作数,若把函数定义为
Node operator=(Node node2)
就可以通过,为什么呢,我要如何处理?

解决方案 »

  1.   

    Node operator=(Node &node)
    这样试一下。
      

  2.   

    Node & operator=(const Node & node2)
    {
    Task=node2.Task;
    Place=node2.Place;
    Thing=node2.Thing;
    Description=node2.Description;
    Others=node2.Others;
    Time=node2.Time;
    TimeFlag=node2.TimeFlag;
    return *this;
    }
      

  3.   

    以上问题解决了,谢谢。
    看书的时候没注意书上定义的是友元函数。
    那如果有如下语句:
      Node *p;
      p=first;
    (
      private:
    Node *first;
    )
    以上的定义会有错,请问除了更改重载的符号外还有没有其他的好办法?另有如下重载的问题:
    class Node
    {
    private:
        Node *next;
        bool operator== (Node node2)
        { 
    return (Task==node2.Task && Place==node2.Place && Time==node2.Time);
        };
    }
    ///////////
    p->next==node2;(or&(p->next)=node2;error C2679: binary '==' : no operator defined which takes a right-hand operand of type 'class Node' (or there is no acceptable conversion)为什么呀??右边的node2定义的是Node类呀。