C ++ std :: stringstream运算符<<超载 [英] C++ std::stringstream operator<< overloading
本文介绍了C ++ std :: stringstream运算符<<超载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下课程(原型):
I have the following class(prototipe):
class Token
{
public:
//members, etc.
friend std::stringstream& operator<< (std::stringstream &out, Token &t);
};
操作符的实现是这样的:
And the operator is implemented like this:
std::stringstream & operator<< (std::stringstream &out, Token &t)
{
out << t.getValue(); //class public method
return out;
}
现在,我正在尝试像这样使用它:
Now, I'm trying to use it like this:
std::stringstream out;
Token t;
//initialization, etc.
out << t;
VS给我一个错误,说<<不匹配.操作员.我怎么了?
And VS gives me error, saying that there is no match for << operator. What am I wrong in?
推荐答案
std::stringstream & operator<< (std::stringstream &out, Token &t)
应该是
std::ostream & operator<< (std::ostream &out, Token const &t)
这篇关于C ++ std :: stringstream运算符<<超载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文