The following code does not compile using Visual Studio 2013. It does compile using Xcode 6.1 (Clang 3.5).
std::string s1("one");
std::string s2("two");
std::string s3("three");
std::string s4("four");
class X
{
typedef std::map<std::string, std::string> MyMapType;
MyMapType map1 = { { s1, s2 }, { s3, s4 } };
MyMapType map2 = { { std::make_pair(s1, s2) }, { std::make_pair(s3, s4) } };
};
The error reported for both declarations is:
error C2664: 'std::map<std::string,std::string,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>::map(std::initializer_list<std::pair<const _Kty,_Ty>>,const std::less<_Ty> &,const std::allocator<std::pair<const _Kty,_Ty>> &)' : cannot convert argument 2 from 'initializer-list' to 'const std::allocator<std::pair<const _Kty,_Ty>> &'
However, the following does compile:
int main()
{
typedef std::map<std::string, std::string> MyMapType;
MyMapType map3 = { { s1, s2 }, { s3, s4 } };
return 0;
}
Please can someone explain this.
Aucun commentaire:
Enregistrer un commentaire