我的目标是重载'+'运算符,以便我可以组合Paragraph对象和Story对象。此功能应该返回一个新的故事对象与附加到开头的段落。重载运算符C++:错误:没有可行的重载'='
Story Paragraph::operator+(const Story& story) {
Paragraph paragraph;
Story stry;
Paragraph storyPara = story.paragraph;
Sentence paraSentence = storyPara.sentence;
paragraph.sentence = this->sentence + paraSentence;
stry.paragraph = paragraph;
return stry;
}
然而,当我跑我的所有代码(A故事的对象应该有一个段落。段落对象应该有一个句子,一个句子对象应该有一个字,等),我得到这个错误:
错误:没有合适的重载 '='
当我尝试做下面的行会发生此:
paragraph.sentence = this->sentence + paraSentence;
我不太确定如何将句子加在一起组成一个段落(最终形成&返回一个新的故事)。有谁知道如何解决这个问题?
_“你可以假设我所有的类都被正确定义了”_如果这是真的,你就不会有错误... –
'Sentence'类是否有复制构造函数或重载的'='运算符? – yizzlez
什么问题?我们看不到任何相关的代码。出示您在过去几天内一直在调试该问题的[最小测试用例](http://stackoverflow.com/help/mcve)。 –