简体   繁体   English

C ++ std :: stringstream operator <<重载

[英]C++ std::stringstream operator<< overloading

I have the following class(prototipe): 我有以下课程(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;

And VS gives me error, saying that there is no match for << operator. VS给了我错误,说没有匹配<<运算符。 What am I wrong in? 我错了什么?

std::stringstream & operator<< (std::stringstream &out, Token &t)

应该

std::ostream & operator<< (std::ostream &out, Token const &t)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM