Compiler Error C2558
'identifier' : no copy constructor available or copy constructor is declared 'explicit'
A copy constructor initializes an object from another object of the same type. (It makes a copy of the object.) The compiler generates a default copy constructor if you do not define any constructors.
To fix this error
The problem can occur when an attempt is made to copy a class whose copy constructor is
private
. In most cases, a class that has aprivate
copy constructor should not be copied. A common programming technique declares aprivate
copy constructor to prevent the direct use of a class. The class may be useless by itself or require another class in order to work correctly.If you determine that it is safe to use a class that has a
private
copy constructor, derive a new class from the class that has theprivate
constructor and make apublic
orprotected
copy constructor available in the new class. Use the derived class in place of the original.The problem can occur when an attempt is made to copy a class whose copy constructor is explicit. Declaring a copy constructor as
explicit
prevents passing/returning objects of a class to/from functions. For more information about explicit constructors, see User-Defined Type Conversions.The problem can occur when an attempt is made to copy a class instance declared
const
by using a copy constructor that does not take aconst
reference parameter. Declare your copy constructor with aconst
type reference instead of a non-const type reference.