c++ - error C2552: 'pairs' : non-aggregates cannot be initialized with initializer list -


how fix compile?

#include <utility>  int main() {     const std::pair<const char*, const char*> pairs[] = { {"string a", "string 1"},                                                            {"string b", "string 2"}      };   } 

giving compiler error:

1>main.cpp(256): error c2552: 'pairs' : non-aggregates cannot initialized initializer list 1>          'std::pair<_ty1,_ty2>' : types user defined constructors not aggregate 1>          1>          [ 1>              _ty1=const char *, 1>              _ty2=const char * 1>          ] 1>main.cpp(257): error c2552: 'pairs' : non-aggregates cannot initialized initializer list 1>          'std::pair<_ty1,_ty2>' : types user defined constructors not aggregate 1>          1>          [ 1>              _ty1=const char *, 1>              _ty2=const char * 1>          ] 

what doing uniform initialization introduced in c++11. c++11 compatibility in vs2012 minimal @ best, , missing in many areas.

you can't use syntax using version of visual studio. instead have use e.g. std::make_pair:

const std::pair<const char*, const char*> pairs[] = {     std::make_pair("string a", "string 1"),     std::make_pair("string b", "string 2") }; 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -