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和两次赋值。
应用推荐