且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么operator =返回引用而不是const引用

更新时间:2022-11-01 16:48:22

一个很好的理由是,其中一个标准中要求在标准容器中可用的类 X 的要求是,表达式 a = b 类型 X& (其中 a 是类型 X b 是类型 X 的右值。

One good reason is that one of the requirements in the standard for a class X to be useable in the standard containers is that the expression a = b must have type X& (where a is an lvalue of type X and b is an rvalue of type X).