The C++11 program
struct Foo {
Foo(Foo const &) = delete;
};
int main() {
Foo foo;
}
generates the error
$ g++ -std=c++11 junk.cpp -o junk
junk.cpp: In function 'int main()':
junk.cpp:6:9: error: no matching function for call to 'Foo::Foo()'
junk.cpp:6:9: note: candidate is:
junk.cpp:2:5: note: Foo::Foo(const Foo&) <deleted>
junk.cpp:2:5: note: candidate expects 1 argument, 0 provided
Now, it looks like the default constructor was prevented from being generated because the copy constructor was deleted. I'm going to assume this is the expected behavior, but where in the C++ standard does it specify that the default constructor should not be generated when the copy constructor is deleted?
From N3485 §12.1 [class.ctor]/5:
If there is no user-declared constructor for class X, a constructor having no parameters is implicitly declared as defaulted (8.4).
Foo(Foo const &) = delete;
is a user-declared constructor, so no default constructor is generated by the compiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With