use variable instead of ostream cout

I have a class that recieves a cout in the constructor ( ostream* )

1
2
3
4
SO::SO(ostream* s)
   {
//constructor logic
   }


so in the main I have:

SO so(&cout);

I have overloaded some operators for this class, and each overload accepts a parameter (int string float or whatever) and should write this value on the screen, but not using cout << but the " s " parameter from the constructor.

How do I do this? I gess the steps are:
1) in the constructor, save s into a private member
2) replace cout with that private member

but I cant find an example and I'm getting errors whatever I try
Last edited on
Show the code where you get errors.
1) in the constructor, save s into a private member
1
2
3
4
5
6
7
8
9
10
11
class SO
{
public:
	SO(ostream* s);
private:
	ostream* s;
};
SO::SO(ostream* s)
:	s(s)
{
}

You can also use references instead of pointers if you want.

2) replace cout with that private member
*s << "something something " << 123;
Topic archived. No new replies allowed.