Two suggestions:
1) you should make your operator overload a free-function (or friend) not a member function (this can be important for argument-dependent lookup of the correct overload).
2) to chain the operators, you need to return a reference to the printclass object from your operator.
With that, you should have:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
class printclass
{
public:
friend
printclass& operator<<( printclass& out, const string & mesg );
};
printclass& operator<<( printclass& out, const string & mesg )
{
cout << mesg;
return out;
}
mike_2000_17
Posting Virtuoso
2,139 posts since Jul 2010
Reputation Points: 1,634
Solved Threads: 457