Your class contains members which cannot be default-constructed or assigned, namely:
Therefore, no default constructor or assignment operator can be implied for your class. For example, you have to write your own constructor:
class Foo
{
const int a;
int & b;
public:
Foo(int val, int & modify_me) :
a(val) , // initialize the constant
b(modify_me) // bind the reference
{ }
};
It is clear that you cannot default-construct Foo
(i.e. Foo x;
). It is also clear that you cannot reassign objects of class Foo
(i.e. x = y;
), because you cannot reassign references or constants.
By giving your class a reference or a constant member, you actually confer reference or constant semantics on the class itself, if you will, so this should be a fairly immediate logical consequence. For example, reassignment probably doesn't even make sense semantically, because your class is supposed to embody a constant concept.
However, note that you can make copies of your class: That's because you can make "copies" of references (i.e. furhter aliases), and copies of constants. Therefore, a copy constructor is available implicitly, by simply applying copy-construction member-by member. So you can say:
int n;
Foo x(15, n);
Foo y(x);
Foo z = x; // these two are identical!
This results in two further objects y
and z
which have y.a == 15
and z.a == 15
, and y.b
and z.b
are all references to n
. (Don't be confused by the two alternative syntaxes at the end; both invoke the copy constructor.)