I'am currently trying to filter input streamed to the 'clog' streambuffer. Therefore i wanted to create a class 'MyClog' which overloads it's << operator and filters the input streamed to it before forwarding the filtered input to the clog streambuffer.
The filtering depends on an internal state of the MyClog class. Also i want to overload the operator using a template, so i just have to implement one method.
example
clog << "This is a Test No." << 1;
myclog << "This is a Test No." << 2
Depending of the internal state of myclog the message is printed out via clog.
My overloaded operator works if i'am not using a template, what am i doing wrong? And what is the difference between template<typename T>
and template<class T>
?
Here is an excerpt of my code.
template<typename T>
class MyClog {
private:
bool state=false;
public:
MyClog& operator<<(const T& arg){
if(state){
clog << arg;
}
return *this;
}