Reputation:
Code:
struct A
{
~A(){ };
};
A::A(){ }; //error: definition of implicitly declared default constructor
int main()
{
A a;
}
Why does the code produces the error? I expected that the program compiles fine. The Standard says N3797::12.8/7 [class.copy]
:
If the class definition does not explicitly declare a copy constructor, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defined as defaulted (8.4). The latter case is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor.
It's a bug or my misunderstanding?
Upvotes: 1
Views: 1171
Reputation: 1458
struct A
{
~A(){ };
A();
};
A::A(){ }; //here you can define default constructor
int main()
{
A a;
}
you have defined explicit destructor not constructor , add constructor declarartion and define it as outside clas
Upvotes: 6
Reputation: 311166
You may not define an implicitly declared constructor by the compiler.
From the C++ Standard (12 Special member functions)
- ... Programs shall not define implicitly-declared special member functions
Upvotes: 5