I compiled and ran the following C++ code, blindly trying to create a flexible array member like you can in C:
#include <iostream>
template <typename T>
struct Vector {
int length;
T ts[];
};
Vector<int> ts = {
3,
{10, 10, 10},
};
int main() {
std::cout << sizeof(ts) << std::endl;
std::cout << ts.data[1] << std::endl;
return 0;
}
The code compiles and runs just fine, and gives the same output that C would in the same circumstance (it outputs 4 and then 10).
Now, according to this answer from 2010 what I have written should not be valid C++. Furthermore, according to this wikipedia article, "C++ does not have flexible array members".
My question is, which C++ feature am I actually using in the above code, specifically on the line that says "T ts[];
"? Does that code actually do what I think it does in general, or is it undefined behavior?