Custom Manipulator with 1 .. N Parameters

Hi guys,

I wanted to create a simple class which would act as a manipulator to log staff when flag is set and not log when it is reset. To do this I tried creating
a class and then using the function of the class as a manipulator.
Since the << takes stand alone function, I have no clue how I can achieve
this. Previous posts on this use a functor but I doubt this will help in
my case.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


class NULLBUF : public std::streambuf
{
};

class Logger
{
public:

	Logger(bool en) : m_enable(en), m_Nobuff(new NULLBUF) {};
	
	std::ostream& Log(std::ostream& out)
	{
		if (!m_enable)
		{
			out.set_rdbuf(m_Nobuff);
		}

		return out;
	}

private:

	bool m_enable;

	NULLBUF * m_Nobuff;

};

int main()
{

	Logger aLogger(false);

	float a = 1.02;

	std::cout << aLogger.Log << a  ;

	system("pause");
}
Topic archived. No new replies allowed.