注意在这种情况下,编译器通常可以(但不是必须要)对其进行优化,适当的处理拷贝构造(Copy Construction)操作(一般是省略掉拷贝构造过程)。如果进行了优化,则一定要保证拷贝构造函数(Copy Constructor)的可达性。
基于44个网页-相关网页
Now, try using a copy construction and operator assignment for class a, declared in Listing 15.
现在,尝试为类a使用一个复制结构和运算符赋值,在清单15中声明该类。
Note: the compiler is actually allowed (but not required) to optimize away the copy construction in this kind of situation.
注意:实际上在这种情况下,编译器是会对拷贝构造进行优化的。
Now, for classes that store large amounts of data, this method may not be the most efficient way to swap data, because swap involves one copy construction and two assignments.
现在,对于存储大量数据的类,此方法可能不是交换数据的最有效方法,因为swap涉及到一个copy construction和两次赋值。
应用推荐