64,685
社区成员
发帖
与我相关
我的任务
分享
The return type from the assignment operator should be the same as the return from assignment for the built-in types (Section 5.4.1, p. 160). Assignment to a built-in type returns a reference to its left-hand operand. Therefore, the assignment operator also returns a reference to the same type as its class.
赋值操作符的返回类型应该与内置类型赋值运算返回的类型相同(第 5.4.1 节)。内置类型的赋值运算返回对右操作数的引用,因此,赋值操作符也返回对同一类类型的引用。
A atmp = b;//这里则不需要返回引用;
class A
{
……
};
int main() {
A b;
A& a = b;//这里,如果重载等号运算符,那么这个返回值应该是A&
A atmp = b;//这里则不需要返回引用;
return 0;
}