C ++ partial initialization with curly braces
1 answer
Pair can be changed to std::pair
( #include <utility>
) if Pair is not defined. Partial initialization is allowed in the corrected program (see below), it prints 1, 2, 0, since it is c
also initialized as a vector with no elements.
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;
}
+4
source to share