#include <vector>
struct foo {
int i;
int j;
int k;
};
int main() {
std::vector<foo> v(1);
v[0] = {0, 0, 0};
return 0;
}
When compiling this using g++, I get the following warning:
warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
As far as I can tell, though, it’s just a normal initializer list. The struct is a POD type.
Is this a bug or am I missing something?
Pre C++11 (and possibly C99) you can only initialize a POD at creation, not at arbitrary runtime points, which is what you’re attempting here (assignment from an initializer list).
You can make a null_foo though: