I have a class A where, the copy assignment operator is deleted. How should I swap two instances of A ?
I tried using std::swap
but that did not work.
class A {
private:
int a;
public:
A& operator=(const A& other) = delete;
A(int _a = 0):a(_a){}
void showA() { std::cout << a << std::endl; }
};
int main()
{
A obj1(10);
A obj2(20);
obj1.showA();
obj2.showA();
//A temp;
//temp = obj1;
//obj1 = obj2;
//obj2 = temp;
obj1.showA();
obj2.showA();
}
I expect obj1
and obj2
to be swapped. Initially obj1.a
is 10
and obj2.a
is 20
, I expect obj1.a
to be 20
and obj2.a
to be 10
when done.