I have a
struct OpDesc {
std::string OPName;
size_t OPArgsMin;
bool IsVaribaleArgsNum;
bool IsOPChange;
std::string ChangeNodeOP;
std::string ChangeNodeLabel;
bool IsOPDelete;
const char* ErrMsg;
};
And want to init a std::map<string, OpDesc>.
I tried doing it this way :
typedef std::map<std::string,struct OpDesc> OpDescMap;
OpDescMap opDesc;
opDesc["StoreOp"] = {"StoreOp",2,false,false,"","",false,""};
/// etc.
I can’t compile that with VS10. I get : error C2059: syntax error : '{'
How can it be solved?
Your syntax is valid C++11 (see Uniform Initialization), however, VS10 does not support it. It was only added to VS12 (see C++ features in VS2012). One option is to upgrade your compiler to one that has better conformance to C++11.
If you can’t upgrade, you’ll have to fallback to C++03 syntax. You can either use an intermediate variable:
Or add a constructor to your structure: