Is it possible to define a static insertion operator which operates on the static members of a class only? Something like:
class MyClass
{
public:
static
What I would probably do in your situation, is create another class that overloads the operator<<
, then make a static member of that type. Like this:
class MyClass
{
public:
static std::string msg;
struct Out {
Out & operator<< (const std::string& token) {
MyClass::msg.append(token);
return *this;
}
};
static Out out;
};
Using it is not quite what you asked for, but close enough I think:
MyClass::out << "message1" << "message2";