我正在为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?
}
这是这样做的吗?