I just can't get my head around why this won't compile.
I have three files:
main.cpp
#include "expression.h"
int main(int argc, char** argv)
{
return 0;
}
expression.h
#ifndef _EXPRESSION_H
#define _EXPRESSION_H
namespace OP
{
char getSymbol(const unsigned char& o)
{
return '-';
}
};
#endif /* _EXPRESSION_H */
And expression.cpp
#include "expression.h"
(Ofc there is more inside of it, but even if I comment everything except for the #include
out it doesn't work)
I compile it with
g++ main.cpp expression.cpp -o main.exe
This is the error I get:
C:\Users\SCHIER~1\AppData\Local\Temp\ccNPDxb6.o:expression.cpp:(.text+0x0): multiple definition of `OP::getSymbol(unsigned char const&)'
C:\Users\SCHIER~1\AppData\Local\Temp\cc6W7Cpm.o:main.cpp:(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
The thing is, it seems to parse expression.h
two times. If I just compile it using main.cpp
OR expression.cpp
I don't get the error. The compiler just ignores my #ifndef and continues...
Any clues?