After reading this article I made a point that int ()
yields 0 because the temporary int
is value initialized and not because int()
calls the default constructor for int
. (The article is flawed according to my understanding.)
I also said that primitive (built-in) types don't have constructors. The original author asked me to check Section $10.4.2 (TC++PL) which says
Built-in types also have default constructors ($6.2.8)
But I still think that the statement "C++ allows even built-in type (primitive types) to have default constructors." is flawed (as per C++03).
I think Bjarne in TC++PL has mixed up "constructor like notation i.e ()
" with actual constructor call. Value initialization was not introduced at that time when Bjarne was writing the book, right? So is the text in TC++PL incorrect as per C++98 and C++03?
What do you guys think?
EDIT
I asked Bjarne personally (via mail) regarding the flawed text in TC++PL and this was his reply
I think you mix up "actual constructor calls" with conceptually having a constructor. Built-in types are considered to have constructors (whatever words the standard uses to describe their behavior).
int()
? As far I can see it is an example of an initializer which in this case results in default initialization. – Brigham()
implies value initialization in this context. Default initialization is different from value initialization. – Lippiint x({0})
is not allowed. Brace initialization has different rules for scalars because there is no constructor resolution for them. – Eulogium