C4430 Error - missing type specifier - int assumed
I am making a math library (Actually copying one and modifying it.), But after all errors there is just one error I can't seem to get rid of. The Type specifier not found. It is in line 201 of my Math.h which is this line:
int Classify(const Polygon &vcPoly);
I really tried searching google, but I didn't found anything. For me it's not quite that obvious whats wrong. Here is the source of the Plane class. In the Math header are also vector, ray, matrix, and some more math classes. The class Polygon comes after the Plane class but I included the definition at the top of the header.
class Plane {
public:
Vector m_vcN, // plane normal vector
m_vcPoint; // point on plane
float m_fD; // distance to origin
//---------------------------------------
Plane(void) { /* nothing to do */ ; }
inline void Set(const Vector &vcN, const Vector &a开发者_如何学JAVAmp;vcP);
inline void Set(const Vector &vcN, const Vector &vcP, float fD);
inline void Set(const Vector &v0, const Vector &v1, const Vector &v2);
inline float Distance(const Vector &vcPoint);
int Classify(const Polygon &vcPoly);
inline int Classify(const Vector &vcPoint);
bool Clip(const Ray*, float, Ray*, Ray*);
bool Intersects(const Vector &vc0, const Vector &vc1,
const Vector &vc2);
bool Intersects(const Plane &plane, Ray *pIntersection);
bool Intersects(const Aabb &aabb);
bool Intersects(const Obb &obb);
}; // class
Hope you could help me.
It seems like the type Polygon
is not know in that line. Did you include the right header files? My guess is that Polygon.h
(or something like that) is missing.
EDIT: if all classes are included in the same header, maybe you have to make sure that the class is defined (with a prototype) before it is needed as a type. That means you can place class prototypes in the beginning of your header file:
// prototype for Polygon
class Polygon;
This is a case of two header including each other:
Plane.h: #include "Polygon.h"
Polygon.h #include "Plane.h"
Since #include
means 'preprocess the named file and insert contents here' this would lead to infinite recursion, which is why a common technique is to use 'include guards' in header file, in the form of:
#ifndef _SOMETHING_H_
#define _SOMETHING_H_
// header contents here
#endif
How this works, is if you include Polygon.h first, it defines the preprocessor symbol, and then goes on to include the files which you #include
at the top of your header. One of these is Plane.h, which then in turn tries to include Polygon.h, but because Polygon's guard symbol is defined, it gets included as an empty file.
This prevents infinite recursion, but because of this there is no definition of Polygon type preceding the included Plane definition.
The solution is in at least one of these headers (and possibly in both) to replace the inclusion of header with a forward definition of the type. So in Plane.h instead of:
#include "Polygon.h"
you do:
class Polygon;
And you may do the same in Polygon.h.
Note that a forward declared type without a definition is what's called an incomplete type, and there are restrictions of how you can use it in the header: you may define pointers or references to it (which is how it's used in the example, but you may not define instances, pass by value, access fields etc.
精彩评论