I am trying to get to the point where essentially MyClass(A) << "hi " << 17 << std::endl; compiles and executes MyClass::finish() method on the accumulated stream. So far, I'm still stuck on the "compiles" part. Here's what I have so far
#include <iostream>
#include <sstream>
#include <string>
enum foo
{
A,
B,
C
};
class MyClass
{
public:
MyClass(foo v) : v_(v), oss_()
{
}
MyClass& operator<<(std::ostream &o)
{
oss_ << o;
return *this;
}
private:
foo v_;
std::ostringstream oss_;
};
int main()
{
MyClass(A) << "hi " << 17 << std::endl;
return 0;
}
Am I going down the wrong path?