How do I initialize a vector of a pair of strings in a C++ class? I tried several things but none worked out.
vector<pair<string,string>> myVec(); //doesn't work
How do I initialize a vector of a pair of strings in a C++ class? I tried several things but none worked out.
vector<pair<string,string>> myVec(); //doesn't work
On
If you use () you run into the most vexing parse. You declared a function myVec that takes no arguments, and returns a vector<pair<string, string>>
Switch to {}
vector<pair<string,string>> myVec{};
There is no need to initialize a vector such a way
It is a function declaration with name
myVecthat does not have parameters and has return typevector<pair<string,string>>It is enough to write simply
because in any case you are creating an empty vector.
Or if you want that the vector had some initial values and your compiler supports C++ 2011 then you can also write for example