显式删除的函数

Explicitly deleted functions

提问人:Madhu Rao 提问时间:1/19/2023 最后编辑:James ZMadhu Rao 更新时间:1/19/2023 访问量:55

问:

我们正在将代码从旧代码迁移到 VS 2019

我们在运算符“<<”上有一个重载函数,它调用basic_ostream函数 执行以下行时。

CStringArray asLine;
 
using ostream       = basic_ostream<char, char_traits<char>>;
ostream os;
    os << (LPCTSTR)asLine[nLine2]; <---- this line is producing the  C2280 error with message
"basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete"

这在旧版应用程序中起作用。如何克服这个问题?

请提出任何解决方法

CStringArray asLine; // class with set and get functions.
ostream os;
int nLine2 = 20; // nline has subscript valve to the asline[]

os << (LPCTSTR)asLine[nLine2];

        
C++ MFC ostream 删除函数 lpcstr

评论

0赞 James Z 1/19/2023
猜这是 MFC。请正确标记您的问题,以便为其获得正确的受众。
2赞 zdf 1/19/2023
basic_ostream<TCHAR>
3赞 IInspectable 1/19/2023
“这在旧版应用程序中起作用。”- 不,不是。编译为不同代码的旧应用程序,今天仍然可以工作。更改的是编译器环境:在旧情况下,定义了 和 预处理器符号。这更改为定义 和 预处理器符号。就编译器而言,从 改为 .MBCS_MBCSUNICODE_UNICODETCHARcharwchar_t
0赞 Tom Tom 1/20/2023
如果你想要一个字符,不要在这里使用强制转换 LPCTSTR,这是 ostream 所必需的。或者您可以尝试将 ostream 替换为 wostream。
0赞 Madhu Rao 1/21/2023
感谢您的建议。使用 Wostream 代替 Ostream 有助于解决这个问题。

答: 暂无答案