[Solved] Error trying to swap Card Objects in a vector c++


To pick out some key lines from you error

In instantiation of 'void std::swap(_Tp&, _Tp&) [with _Tp = Card]':

use of deleted function 'Card& Card::operator=(Card&&)'

'Card& Card::operator=(Card&&)' is implicitly deleted because the default definition would be ill-formed:

non-static const member 'const int Card::numFace', can't use default assignment operator

You are trying to use std::swap with your cards.
Internally that will try to use operator=, meaning

Cards a, b;
a = b; // Here we are using the operator=

So the error message goes on to say, use of deleted function operator=
It is implicitly deleted because the default definition would be ill-formed.
It is ill formed because you have const ints that can’t be assigned to in your class.

const int c = 5;
c = 10; // This is illegal for a const

The error message also hint at a solution by saying non-static const member …

You can solve this is a number of ways, where making the const int be static seems like a good option in your case.

solved Error trying to swap Card Objects in a vector c++