I have a global object defined in an "object.h" file of the form:
#ifndef objetoo__h
#define objetoo__h
typedef struct objeto {
int a;
} objeto;
objeto objetin;
#endif
Then I define a class in "class.h" and its implementation in "class.cpp". In class.h I proceed as follows:
#ifndef clase__h
#define clase__h
#include "objeto.h"
extern objeto objetin;
class clase { ...
}
#endif
In class.cpp I simply put in the preprocessor directives:
#include "clase.h"
It's in class.cpp where I use the object global object. The problem I have is that later, making use of a third main.cpp file in which I include "object.h" and "class.h" and again declare extern objetin, the g ++ compiler gives me error by multiple definitions of objective , however, if instead of using a separate file for the implementation of class.h, I put the definitions of the methods in class.h, this problem disappears. Why is this happening?