I’m a little confused about how C++ handles includes.
I have something like:
typedef struct {
//struct fields
} Vertex;
#include "GenericObject.h"
Now in GenericObject.h I have:
class GenericObject {
public:
Vertex* vertices;
}
When I try to compile, the compiler says:
ISO C++ forbids declaration of ‘Vertex’ with no type
How do I get GenericObject.h to know about Vertex?
I was under the impression that anything defined before an #include, was available in the included files.
And lastly, could you give me some tips on how to correctly use #include without introducing too much redundancy or circular includes.
Thanks.
Two things, first you want it to just be…
That is a properly defined struct in C++.
Now you either need to include Vertex.h, or what ever file contains the vertex struct, in your generic object header,
or forward declare it as so…
don’t #include “GenericObject.h” from “Vertex.h”.