Compiler Error C2512
'identifier' : no appropriate default constructor available
No default constructor is available for the specified class, structure, or union. The compiler supplies a default constructor if user-defined constructors are not provided.
If you provide a constructor that takes a non-void parameter, and you want to allow your class to be created with no parameters, you must also provide a default constructor. The default constructor can be a constructor with default values for all parameters.
The following sample generates C2512:
// C2512.cpp
// C2512 expected
struct B {
B (char *);
// Uncomment the following line to resolve.
// B() {};
};
int main() {
B b;
}
The following sample shows a more subtle C2512:
// C2512b.cpp
// compile with: /c
struct S {
struct X;
void f() {
X *x = new X(); // C2512 X not defined yet
}
};
struct S::X {};
struct T {
struct X;
void f();
};
struct T::X {};
void T::f() {
X *x = new X();
}