Why does the compiler choose bool over string for implicit typecast of L“”?

后端 未结 5 2158
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 19:12

Having recently introduced an overload of a method the application started to fail. Finally tracking it down, the new method is being called where I did not expect it to be.

5条回答
  •  日久生厌
    2020-12-01 19:39

    Since bool is a built-in type, the conversion from wchar_t to bool is preferred. I would say that the simplest solution is to add an overload that takes a wchar_t array and cast explicitly in there:

    setValue( const std::wstring& name, const wchar_t s[] )
    {
         setValue(name, wstring(s));
    }
    

提交回复
热议问题