I'm trying to separate the class implementation definition into separate files, however I'm getting undefined reference in ; operator.
What I've tried:
Change the order of objects at link time:
only generates an undefined reference in the class constructor
Move the definition to the same file where the main is: compiles, links and runs smoothly
Makefile performs the following:
g++ -c -I. -std=gnu++0x -Wfatal-errors log.cpp
g++ -c -I. -std=gnu++0x -Wfatal-errors main.cpp
g++ -o main.app log.o main.o
log.h file:
class _LOG
{
public:
_LOG(int level,std::string file,int line);
template<typename T>
_LOG& operator<<(T t);
static int last_log;
static std::ostream * out;
};
log.cpp file:
_LOG::_LOG(int level,std::string file,int line){
// implementacao do construtor omitido
}
template<typename T>
_LOG& _LOG::operator<<(T t)
{
*out << t;
return *this;
}
The final result I get when I put the implementation into main is that I can use it as follows after using a macro:
#define LOG_INFO _LOG(LOG_I,__FILE__,__LINE__)
LOG_INFO << "Bla bla bla" << " outro bla";
ps: this code is for studies only (hobby)