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?
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