How do I fix this to get this to compile?
#include <utility>
int main() {
const std::pair<const char*, const char*> pairs[] = { {"String A", "String 1"},
{"String B", "String 2"}
};
}
Giving this compiler error:
1>main.cpp(256): error C2552: 'pairs' : non-aggregates cannot be initialized with initializer list
1> 'std::pair<_Ty1,_Ty2>' : Types with user defined constructors are not aggregate
1> with
1> [
1> _Ty1=const char *,
1> _Ty2=const char *
1> ]
1>main.cpp(257): error C2552: 'pairs' : non-aggregates cannot be initialized with initializer list
1> 'std::pair<_Ty1,_Ty2>' : Types with user defined constructors are not aggregate
1> with
1> [
1> _Ty1=const char *,
1> _Ty2=const char *
1> ]
What you are doing is uniform initialization which was introduced in C++11. The C++11 compatibility in VS2012 is minimal at best, and missing completely in many areas.
You simply can't use a syntax like that using that version of Visual Studio. Instead you have to use e.g.
std::make_pair
: