它已被反复重复,原始类型没有构造函数.例如_bar,当我调用时,这不会初始化为0 Foo():
class Foo{
int _bar;
};
Run Code Online (Sandbox Code Playgroud)
所以显然int()不是构造函数.但它的名字是什么?
在这个例子中我会说i:(构造?初始化?fooed?)
for(int i{}; i < 13; ++i)
Run Code Online (Sandbox Code Playgroud)
Loki Astari 在这里提到该技术有某种名称.
编辑回应Mike Seymour:
#include <iostream>
using namespace std;
class Foo{
int _bar;
public:
void printBar(){ cout << _bar << endl; }
};
int main()
{
Foo foo;
foo.printBar();
Foo().printBar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在Visual Studio 2013上运行此代码产生:
3382592
3382592
有趣的是gcc 4.8.1收益率:
134514651
0