value-initialization

Value initialization and Non POD types

两盒软妹~` 提交于 2019-11-26 06:06:52
问题 An hour ago I posted an answer here which according to me was correct. However my answer was downvoted by Martin B. He said You\'re just lucky and are getting zeros because the memory that i was placed in happened to be zero-initialized. This is not guaranteed by the standard. However after reading Michael Burr\'s answer here and trying the following sample code 1) #include <cassert> struct B { ~B(); int m; }; int main() { B * b = new B(); assert(b->m == 0); } I got a debug error on MSVC++

Do built-in types have default constructors?

六月ゝ 毕业季﹏ 提交于 2019-11-26 01:47:25
问题 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

Do built-in types have default constructors?

删除回忆录丶 提交于 2019-11-25 22:10:56
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