0
我有一个类的头文件叫做串行内超载:serial.h了解操作Singleton模式
这里面的头文件,我有以下类型的操作超载:
private:
...
Serial & operator = (const Serial &);
我知道,这就像here
我还looked up操作过载,发现赋值运算符的以下示例的单例模式的一部分:
void operator=(const Distance &D)
但是“&”是什么意思?它是如何工作的?
所以'Serial operator =(const Serial);'会给一个Serial对象的一个常量副本? AND如果我会写: 'Serial&operator =(const Serial&);'OR'Serial&operator =(const Serial&);'OR'Serial&operator =(const Serial&); Serial&operator =(const Serial&);'? – goulashsoup
'串行运算符=(常量串行)'将获取一个串行的恒定副本并返回一个非常量串行对象。根据你的实现和编译器优化,返回值可能是复制的,但是它是一个右值而不是左值,所以像'serial1 = serial2 = serial3'这样的东西就会失效。最好是你按照πάνταῥεῖ提供的重复链接,在那里详细解释一切。空格的放置在这里不会改变任何东西。 – Anedar