Snapples
asked on
Massive errors on #include, what's wrong with this class?
Hello all,
I'm actually looking for an explanation more than a solution, as I know how to work around the problem but I don't know why I'm getting these errors, as far as I see it I shouldn't be getting them at.
This is a DirectX10 application but the errors aren't related to DX. I have a class called Renderer which I use to draw primitive shapes such as lines, grids, spheres, etc. Each of these is an object in Renderer. It's a singleton class and has to be accessable everywhere.
I have included it to my main class's header and that works fine, however when I try to include Renderer.h to any other header file I get tons of syntax and missing type specifier errors on the shape objects, as if I haven't included their header files, but I have.
I get these 3 errors per shape object.
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
My first idea would be missing include guards, but all my header files have #pragma once.
I can fix the problem with forward class declaration on the shape objects but it still doesn't make sense why I'm getting those errors in the first place.
I'd like to know what's causing this so I can avoid it in the future.
Thanks in advance.
I'm actually looking for an explanation more than a solution, as I know how to work around the problem but I don't know why I'm getting these errors, as far as I see it I shouldn't be getting them at.
This is a DirectX10 application but the errors aren't related to DX. I have a class called Renderer which I use to draw primitive shapes such as lines, grids, spheres, etc. Each of these is an object in Renderer. It's a singleton class and has to be accessable everywhere.
I have included it to my main class's header and that works fine, however when I try to include Renderer.h to any other header file I get tons of syntax and missing type specifier errors on the shape objects, as if I haven't included their header files, but I have.
I get these 3 errors per shape object.
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
My first idea would be missing include guards, but all my header files have #pragma once.
I can fix the problem with forward class declaration on the shape objects but it still doesn't make sense why I'm getting those errors in the first place.
I'd like to know what's causing this so I can avoid it in the future.
Thanks in advance.
// ********************
// Renderer.h
// ********************
#pragma once
// Helper.h: includes all DirectX related headers
#include "Helper.h"
// The shape classes
#include "Line.h"
#include "Quad.h"
#include "Sphere.h"
#include "Axis.h"
#include "Grid.h"
// Defines the singleton for easy calling
#define RENDERER (Renderer::GetSingleton())
// Defines for current mode * See SetMode()
#define MODE_EDIT_GROUND 2
#define MODE_EDIT_FRONT 4
#define MODE_EDIT_SIDE 8
#define MODE_EDIT_AXIS 16
#define MODE_EDIT_NONE 32
// Forward declarations, fixes the problem when uncommented
// But they're already included so why need these??
//class Line;
//class Quad;
//class Sphere;
//class Axis;
//class Grid;
class Renderer
{
public:
static Renderer* GetSingleton();
virtual ~Renderer(void);
void Initialize();
void DrawLine(D3DXVECTOR3 point1,D3DXVECTOR3 point2, D3DXCOLOR color);
void DrawQuad(D3DXVECTOR3 point1,D3DXVECTOR3 point2,D3DXVECTOR3 point3,D3DXVECTOR3 point4,D3DXCOLOR color);
void DrawSphere(D3DXVECTOR3 center, float radius, D3DXCOLOR color);
void DrawCube(D3DXVECTOR3 v1, D3DXVECTOR3 v2, D3DXVECTOR3 v3, D3DXVECTOR3 v4, D3DXVECTOR3 v5, D3DXVECTOR3 v6,
D3DXVECTOR3 v7, D3DXVECTOR3 v8, D3DXCOLOR color);
void Draw();
void Update();
void SetMode(DWORD flags);
protected:
private:
// Private constructor
Renderer(void);
static Renderer* m_pRenderer;
// 3 ERRORS on each of these 7 lines
Line* m_Line;
Quad* m_Quad;
Sphere* m_Sphere;
Axis* m_Axis;
Grid* m_GroundGrid;
Grid* m_XYGrid;
Grid* m_ZYGrid;
DWORD m_ModeFlags;
bool m_bDebug;
private:
Renderer(const Renderer& t);
Renderer& operator=(const Renderer& t);
};
I think because you don't have D3DX10Math.h included in this file. But you do use the types declared in this (or other Direct X header-files). So if you include this Renderer.h in a file where you have included other headers, your program compiles well.
ASKER
D3DX10Math.h is included in the Helper.h file along with other DirectX headers. What you're saying would make a lot of sense but I tried including all the headers from my main class's header in the other header where I want to include Renderer.h but there's no difference.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.