class Widget { ... void swap(Widget& rhs);}Widget& Widget::operator=(const Widget& rhs){ Widget tmp(rhs); swap(rhs); return *this; } 采用copy and swap技术,交互临时变量和原本变量的数据空间,临时变量在超出作用域之后会自动的执行析构函数。