OK, this is really annoying. I have the (almost) simplest class possible. Two files: a.cpp and a.h a.h:
#ifdef A_H
#define A_H
class a{
public:
a();
};
#en
Replace #ifdef
with #ifndef
, then try again.
There are some IDEs I find very helpful, that parse the code while you type and show in 'gray' font the code that is not going to be compiled, as of the current macro definitions. Moreover, running
gcc -E
followed by the gcc
arguments you already know, will show you what's the code going to be compiled after preprocessing (macros are resolved by the preprocessor, the initial step of the compilation-building toolchain).
Its because
#ifdef A_H
needs to be
#ifndef A_H
notice the "n", as in if NOT defined.
The former will only compile the code if A_H is defined, which it isn't since you only define it on the next line.