This documentation is archived and is not being maintained.

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 by checking the following possible causes

  1. Trying to copy a class whose copy constructor is private. In most cases, a class with a private copy constructor should not be copied. A common programming technique declares a private 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 properly.

  2. Trying to copy a class whose copy constructor is explicit. Declaring a copy constructor with explicit prevents passing/returning objects of a class to/from functions.

To fix by using the following possible solutions

  • If you determine that it is safe to use a class with a private copy constructor, derive a new class from the class with a private constructor and make a public or protected copy constructor available in the new class. Use the derived class in place of the original.

For more information, see Compiler Errors when Implementing a CObject-Derived Class.