如果定义了一个向量为std::vector<std::string>
,你可能会想知道以下代码为什么是有效的:
if ( vecMetaData[0] != "Some string" )
{
...
但不是这个:
switch ( vecMetaData[1] )
{
...
Visual studio 抱怨:
error C2450: switch expression of type 'std::basic_string<_Elem,_Traits,_Ax>' is illegal
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called