Okay, I'm trying to make a really, really basic debugging class.
However, it's just not compiling with MinGW (GCC 3.2.3).
Here's the code:
Debug.h
#ifndef __DEBUG_H__
#define __DEBUG_H__
#include <iostream>
class CDebug
{
public:
CDebug(std::ostream& ostrm) : out(ostrm) : enabled(false) {}
void Enable(bool set) { this->enabled = set; }
bool Enabled() { return this->enabled; }
template<class T>
CDebug& operator << (T item)
{
if(this->Enabled())
out << item;
return *this;
}
private:
std::ostream& out;
bool enabled;
};
extern CDebug Debug;
#endif//__DEBUG_H__
Debug.cpp
#include "Debug.h"
CDebug Debug(std::clog);
main.cpp
#include <iostream>
#include "Debug.h"
int main(int argc,char* argv[])
{
Debug.Enable(true);
Debug << "This is a test" << std::endl;
Debug.Enable(false);
Debug << "This is another test" << std::endl;
return 0;
}
This is what I get when I try to compile (using latest stable MinGW and MSYS):
$ g++ -o test.exe main.cpp -lstdc++
main.cpp: In function `int main(int, char**)':
main.cpp:30: no match for `CDebug& << <unknown type>' operator
main.cpp:32: no match for `CDebug& << <unknown type>' operator
main.cpp:34:2: warning: no newline at end of file
What exactly is wrong here?