所以基本上这就是我想做的:
void someMethod() {
StreamClass streamClass{};
streamClass << "Something" << "\n"; //do something
streamClass.doA << "Something" << "\n"; //do another thing
streamClass.doB << "Something" << "\n"; //do something else
//If the first one is impossible, what about this?
streamClass << "Something" << "\n"; //do something
streamClass::doA << "Something" << "\n"; //do another thing
streamClass::doB << "Something" << "\n"; //do something else
//Or this?
streamClass<enumA> << "Something" << "\n"; //do something
streamClass<enumB> << "Something" << "\n"; //do another thing
streamClass<enumC> << "Something" << "\n"; //do something else
}
头文件:
class StreamClass {
public:
StreamClass(); //Init class
//... and many other things
template<typename T>
StreamClass& operator<<(T t) {
//... do something that uses data and t
}
//And do something here?
protected:
Data data; //some data owned by this object
};
那么,有没有办法做这样的事情呢?以及如何以最快的方式做到这一点?