以前遗漏了这一特性,在《C++标准程序库—自修教程与参考手册》看到相关讲解,做个笔记。
ExplicticInitialization,也即使用“内置”的初始化函数为基本类型提供初始值,比起使用int i2 = 0;这种魔术数字来来,使用int()也许是更优雅的选择。
#include <iostream>
using namespace std;
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
int i1;
cout << i1 << endl;
int i2 = int();
cout << i2 << endl;
float f1;
cout << f1 << endl;
float f2 = float();
cout << f2 << endl;
system("pause");
return 0;
}
///////////////////////////End Sub//////////////////////////////////
/************************************************************************/
/* output:
-858993460
0
-1.07374e+008
0
*/
/************************************************************************/
码农场