0

由于某种原因,我的赋值运算符在我尝试使用它时会产生总线错误:

hand1 = hand2;


//overload assignment operator
Hand Hand::operator=(Hand other_hand)
{

    if(&other_hand != this){
        name = other_hand.name;
        cards = other_hand.cards;

    }

    return *this;   
}

错误发生在 return 语句之后

4

1 回答 1

1

首先,分配应该有一个看起来像这样的签名:

Hand & Hand::operator=(const Hand &other_hand)

您可能不想像所指出的那样传递和返回副本,但也希望允许操作链接,即:

hand1 = hand2 = hand3 ....

这是一个基本的参考。还提到了复制和交换,这个先前的线程很好地解释了它。

于 2013-03-04T01:41:05.477 回答