零。 "默认初始化"是正确的术语。并且,是的,它应该被初始化为零。 评论的第二部分是什么意思? 是的。 Victor 我不相信你,所以我查了一下,果然,这是正确的。 到OP: 标准说初始化程序为()的任何对象是 " value-initialized",对于POD类型,value-initialized"定义 为零初始化。有关详细信息,请参阅第8.5节。 Alan I recently came across some code in a template that default constructed anobject of type T to pass to another function...SomeFunction(T());The code that instantiates that template specifies T as an int.Proper program behavior relies on that "default constructed" int being zero.That lead me to the following example...int main(){int i; //Uninitialized! Expected for automatic of built-in typeint j = int(); //Initialized to zero! Not sure what to expectreturn 0;}Is such "default construction" of built-in types standard C++?char() == 0int()==0etc...Thanks 解决方案Yes.VictorComment could have been extended to say "on other compilers, platforms, etc.."given that I didn''t know if the initialization to zero was standard. zero. "Default-initialised" is the proper term. And, yes, it is supposed to be initialised to zero. What do you mean by the second part of the comment? Yes. VictorI didn''t believe you, so I looked it up, and sure enough, that is correct.To the OP:The standard says that any object whose initializer is () is"value-initialized", and for POD types, "value-initialized" is definedas being "zero-initialized". Refer to Section 8.5 for more info.Alan 这篇关于“默认构造”内置类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 08:42