'C++ User Defined Class Copy Assignment Missing?

I have written two custom classes, called A and B My B class has a member variable a, and it has a function:

void B::setA(A s)
{
    a = s;
}

However, this line is giving me an error:

'operator =' function is unavailable in 'A'.

From my understanding, this means somehow the compiler is not creating a default copy assignment function for my A class. However, I don't see why... the only constructor I've written in A looks like...

class A
{
    //...
public:
    A() {};
    //...
};

Now in truth, A and B are large classes with a lot of member variables, and the names aren't really A and B. Short of posting the entire source for both of these classes, could anyone tell me what types of things I might look for when trying to diagnose that error message? Just to be clear, I never use pointers or low-level features like that so, as far as I know, the default copy-assignment should work fine for class A.

edit:

Someone mentioned that one of the member variables of A might be to blame, so here are all of the types:

const std::string
static const bool
static std::map<int,std::string>
std::vector
std::map<int, C>

where C is a struct that I defined in the same header file that A is in. It just contains a few integers and strings.

c++


Solution 1:[1]

You have in class A a non-static data member declared as

const std::string

that is with the qualifier const. In this case the implicit copy assignment operator is defined by the compiler as deleted.

Solution 2:[2]

const members don't mix well with copy assignment operators. Not only won't the compiler generate one for you, it would also be semantically hard to come up with an "assignment" which does not actually assign everything.

Nothing stops you from writing an assignment operator which does not assign to your const member, of course, but that would mean one of two things:

  1. The assigned object does not appear to the client as an identical copy of the source, which is not what one would except from a copy assignment operator, so that would be a case of operator-overloading abuse.
  2. The member variable does not have an observable effect to the outside. In that case, one must wonder why it exists in the first place, or rather why it is not mutable rather than const.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vlad from Moscow
Solution 2 Christian Hackl