我正在编写一个链表,我在List类中有一个Iterator类.我想重载=运算符,但我不知道启动它的正确语法.
这就是我的代码中的内容
class List{
//member stuff
class Iterator{
private: Node* current;
public: Iterator& operator=(const Iterator& right);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试这个,但我不确定这是否正确.
List::Iterator::operator=(const Iterator& right){
//stuff
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以澄清吗?
为了澄清,你的想法是正确的,但你忘了在函数声明中有一个返回类型:
List::Iterator::operator=(const Iterator& right){
//stuff
}
Run Code Online (Sandbox Code Playgroud)
需要是
List::Iterator& List::Iterator::operator=(const Iterator& right){
//stuff
}
Run Code Online (Sandbox Code Playgroud)