Compiler Warning (level 4) C4510
TOC
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

Compiler Warning (level 4) C4510

Error Message

'class' : default constructor could not be generated

The compiler cannot generate a default constructor for the specified class and no user-defined constructor was created. You will not be able to create objects of this type.

There are several situations that prevent the compiler from generating a default constructor, including:

  • A const data member.

  • A data member that is a reference.

You need to create a user-defined default constructor for the class that initializes these members.

The following sample generates C4510:

// C4510.cpp
// compile with: /W4
struct A {
   const int i;
   int &j;
   A& operator=( const A& ); // C4510 expected
   // uncomment the following line to resolve this C4510
   // A(int ii, int &jj) : i(ii), j(jj) {}
};   // C4510

int main() {
}
Show:
© 2016 Microsoft