0
I’m trying to separate the definition of the class implementation into separate files, but I’m getting Undefined Ference on the operator <<.
What I’ve already tried:
Change the order of objects at link time:
only generates one more Undefined Ference in the class builder
Move the setting to the same file where the main::
compile, link and run smoothly
Makefile executes 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 file. h:
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 file.cpp:
_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 obtained when I put the implementation in 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 merely for studies (hobby)
Is this the whole file? There’s no
#include
? Curiously without the filemain.cpp
complicates a little, the error may be in it too.– Maniero
@bigown sorry for omitting these snippets of code, I will try to be clearer on the next question, I did not put it because I thought it was implicit when I said that changing the order of objects generated error in the constructor, so #include should be correct.
– staltux
It is not good practice to use '_' and uppercase initiator identifiers (e.g.: _LOG) as these identifiers are reserved by the default language and library.
– zentrunix
The funny thing is that everything in capital letters is exactly what I hate about WIN_API, everything looks like a macro, and I ended up doing it here
– staltux