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

后端 未结 5 2160
没有蜡笔的小新
没有蜡笔的小新 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:46

    L"" is a pointer to a wide character string. The compiler believes that the conversion to a bool takes precedence over a conversion to a std::wstring.

    To fix the problem, introduce a new setValue:

    void setValue(std::wstring const& name, const wchar_t * value);
    

提交回复
热议问题