Compiler Error C2621

member 'identifier' of union 'union' has copy constructor

A union member cannot have a copy constructor.

The following sample generates C2621:

// C2621.cpp
class A {
   A( const A& );   // A has a copy constructor
};
union U {
   A a;   // C2621
};

C2621 can also be generates for code that compiled in Visual C++ 6.0, but that no longer compiles. The Visual C++ 6.0 Standard C++ Library did not use a union of its template parameters. Class types that have a copy constructor cannot be a template parameter for basic_string.

The following sample generates C2621:

// C2621b.cpp
// compile with: /EHsc
#include <vector>
#include <string>
using namespace std;
typedef vector<int> mytype;

int main() {
   basic_string < mytype > b;   // C2621 class type (vector) with
                               //  copy constructor as template param
   basic_string < char > c;   // OK
}