An object of type class can be initialized by default if it has a default constructor provided by the user. From [dcl.init] / 7:
If the program calls the default initialization of an object of type const-type T
, T
must be a class type with a user-supplied default constructor.
Your Foo
class does not; having a parenthesis initializer or the same does not create a user-created default constructor. Rather, your class has an implicit default constructor, the action of which includes initializing as requested using the brace-or-equals-initializer element. (Klang is right.)
([dcl.fct.def.default], in particular clause 5, refers to the definitions of “user-provided”, “explicitly defaulted”, “implicitly declared”, and “defined as deleted.” The entire section is worth knowing.)
By the way, it's easy to avoid the default initialization in C ++ 11:
const Foo foo {};
source share