If you define a custom manipulator that works with, say, the ostream class, it will work with all classes derived from ostream. If, however, you need manipulators that work only with a derived class xstream, then you must add the overloaded insertion operator, shown below, which is not a member of the class.
xstream& operator<< ( xstream& xs, xstream& (*_f)( xstream& ) ) {
(*_f)( xs );
return xs;
}
Now the manipulator code looks like this:
xstream& bold( xstream& xs ) {
return xs << '\033' << '[';
}
If the manipulator needs to access xstream protected data members functions functions, you can declare the bold function as a friend of the xstream class.