看來此代碼(所以它編譯罰款),我要問這裏是:是否有保證的sizeof(STD ::陣列)是一樣的sizeof(equivalent_Carray)?std :: array <T, N>的大小是否保證等於T [N]的大小?
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();
}
請提出一個有用的問題標題。 –