尝试了 C++ 标准,但无法弄明白。这些是等价的吗?
double x[2] = {0.0, 0.0};
和
double x[2] = {};
这些怎么样?
struct A {
double x[2];
};
A a = {0.0, 0.0};
和
A a = {};
谢谢!
最佳答案
C++ 标准说 (8.5.1):
If there are fewer initializers in the list than there are members in the aggregate, then each member not explicitly initialized shall be value-initialized
double 的值初始化是将其设置为 0.0
。
是的!在 C++ 中,它们是等效的。
[我还没来得及检查 C99 标准。]
关于c++ - 值初始化聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6436554/