Rom*_*kov 1 c++ stl visual-studio-2010 visual-c++
class mystream : public std::stringstream
{
public:
void write_something()
{
this << "something";
}
};
Run Code Online (Sandbox Code Playgroud)
This results in the following two compile errors on VC++10:
error C2297: '<<' : illegal, right operand has type 'const char [10]'
error C2296: '<<' : illegal, left operand has type 'mystream *const '
Run Code Online (Sandbox Code Playgroud)
Judging from the second one, this is because what this
points at can't be changed, but the << operator does (or at least is declared as if it does). Correct?
Is there some other way I can still use the <<
and >>
operators on this
?
mystream *const
表示这this
是一个指向非常量对象的常量指针.问题是您正在尝试将流插入到指针中 - 您必须插入到流中.请尝试以下方法.
*this << "something";
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
499 次 |
最近记录: |