我见过很多教程,并试图在stackoverflow上找到答案,但没有成功。 我不确定的是;有没有什么时候通过价值或通过引用返回,当超载运营商? 例如, Class &operator+(){
Class obj;
//...
return obj;
}
或相同的事情,但按价值 Class operator+(){
Class obj;
//.
考虑我们有一个由值返回一个函数: int func() {
int x = 10; // create local variable x with value of 5
return x; // create temporary copy of x which is returned, local variable x is destroyed
}
int main()
考虑以下情况:有一个类CDriver负责枚举所有连接的输出设备(由COutput类表示)。该代码可能是这个样子: class COutput
{
// COutput stuff
};
class CDriver
{
public:
CDriver(); // enumerate outputs and store in m_outputs
// som