gpt4 book ai didi

c++ - std::array 的大小是否保证等于 T[N] 的大小?

转载 作者:搜寻专家 更新时间:2023-10-31 00:31:13 24 4
gpt4 key购买 nike

<分区>

看起来这段代码有效(所以它编译得很好),我在这里问的是:是否保证 sizeof(std::array) 与 sizeof(equivalent_Carray) 相同?

struct MyClass {
std::array<float, 4> arr;
float carr[4];

std::array<float, 4> cfunction() {
std::array<float, sizeof(carr) / sizeof(float)> out;
return out;
}

std::array<float, 4> function() {
// Is this guaranteed to be the same as sizeof(carr) / sizeof(float)??
std::array<float, sizeof(arr) / sizeof(float)> out;
std::cout << sizeof(arr);
return out;
}
};

int main()
{
MyClass obj;
obj.function();
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com