I have simple logging class as below.
#include <iostream>
#include <string>
using namespace std;
class log
{
public:
log(){};
~log(){};
log & operator << ( int x ){ cout << x; return * this;}
log & operator << ( string x ){ cout << x; return * this;}
log & operator << ( log & (log::*pf)() ){ (this->*pf)(); return * this;}
log & end( ) { cout << "\r\n"; return * this;}
};
log l;
#define end &log::end;
#define error( z ) l << "ERROR " z << end;
#define warn( z ) l << "WARN " z << end;
int main()
{
int y = 20;
error ( << y );
}
Is there any way that I can write my code in main like this?
error << y;
Basic idea here, is to avoid user to use macro end
i.e. I do not want user to code like below
error << y << end;