I have a class
class MyClass
{
public :
int a;
int b;
}
For using the copy-swap idiom I then create the function
void MyClass::swap(MyClass& other)
{
std::swap(a,other.a);
std::swap(b,other.b);
}
If, later, I change my class and remove the member a
, then the compiler will complain in the swap
function, and that's fine.
But if I add a new member, my swap
function is not correct anymore. What can I do in order to not forget adding the new member to the swap function ?