【发布时间】:2012-06-22 11:10:03
【问题描述】:
可能重复:
Why is it an error to use an empty set of brackets to call a constructor with no arguments?
在对this question 的回复中,据说
ints 被默认构造为 0,就像你用 int() 初始化它们一样。其他基本类型的初始化方式类似(例如,double()、long()、bool() 等)。
就在我向我的一位同事解释这一点时,我编写了以下代码 compiled (gcc-4.3.4) and ran,并观察到了意外行为。
#include <iostream>
int main() {
int i();
std::cout << i << std::endl; // output is 1
}
为什么输出是1 而不是0?
【问题讨论】:
-
我很惊讶它甚至可以编译,因为看起来你偶然发现了most vexing parse。
-
恭喜你发现the most vexing parse。
-
如果 C++ 在 Steam 上,你现在就能获得成就。
标签: c++