Is this initialization valid by standard? Would it create empty vector so that I could push data (vector<Pair<float, string> >s) into it later?
struct A
{
int a;
int b;
vector<vector<Pair<float, string> > > c;
};
A obj = {1, 2};
Pair could be changed to std::pair (#include <utility>) in case Pair is not defined
In the corrected program (below), partial initization allowed, it prints, 1, 2, 0, as c gets initialized too as a no-element vector.
struct A
{
int a;
int b;
vector<vector<std::pair<float, string> > > c;
};
A obj = {1, 2};
int main()
{
cout << obj.a << ", " << obj.b << ", " << obj.c.size() << endl;
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With