抽象类具有操作符链操作。子类实现操作符链接

时间:2017-07-18 21:28:04

标签: c++ operator-overloading

我正在为std :: stringstream创建一个接口,我想实现<<操作

我正在考虑做这样的事情:

“IStringStream.h”

class IStringStream {

public:

virtual IStringStream& operator << (const IStringStream &rhs) = 0;

}

virtual ~IStringStream(){}

MyStringStream.h

class MyStringStream:IStringStream {
private:
    std::stringstream ss;
public:
    virtual IStringStream& operator << (const IStringStream &rhs) override;
}

MyStringStream.cpp

MyStringStream::MyStringStream() {
     ss.str("");
}

MyStringStream::MyStringStream(Generic Type(?)T) {
     ss << T;
}

IStringStream & IStringStream::operator << (const IStringStream &rhs) {
     ss << rhs.ss; // Something like this?
}

这是这样做的吗?

0 个答案:

没有答案