【发布时间】:2023-03-21 21:24:01
【问题描述】:
在这里:http://en.m.wikipedia.org/wiki/Rule_of_three_(C++_programming)
/** Copy Assignment Operator */
Foo& operator= (const Foo& other) {
Foo temporary (other);
std::swap (data, temporary.data);
return *this;
}
在示例中,它使用std::swap 将数据与临时交换。为什么我们要创建一个临时的和交换?只是复制不是更快吗?我在其他地方也看到了这个,很困惑。
【问题讨论】:
标签: c++