int a=int(); what happens in C++98?

孤街浪徒 提交于 2019-12-04 03:16:10

5.2.3 Explicit type conversion (functional notation)

2 The expression T(), where T is a simple-type-specifier (7.1.5.2) for a non-array complete object type or the (possibly cv-qualified) void type, creates an rvalue of the specified type, whose value is determined by default-initialization (8.5; no initialization is done for the void() case). [...]

8.5 Initializers

5 [...] To default-initialize an object of type T means:

-- if T is a non-POD class type (clause 9), the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);

-- if T is an array type, each element is default-initialized;

-- otherwise, the storage for the object is zero-initialized.

There is no problem. int() has been guaranteed to evaluate to zero right from the very first C++ standard. The fact that it happened through default-initialization, rather than value-initialization, is a technical detail that is completely irrelevant for your question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!