How can CString be passed to format string %s?

前端 未结 4 469
孤街浪徒
孤街浪徒 2020-12-02 01:25
class MyString
{
public:
    MyString(const std::wstring& s2)
    {
        s = s2;
    }

    operator LPCWSTR() const
    {
        return s.c_str();
    }
pri         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 02:09

    Generally speaking it's undefined behavior. According to this article Visual C++ just invokes the conversion from CString to a POD type to cover you - that is permissible implementation of undefined behavior.

提交回复
热议问题