当我继承类时,我会收到这些错误消息。
1>c:\users\owner\documents\visual studio 2010\projects\monopoly\monopoly\d3ddevice.h(6): error C2504: 'Window' : base class undefined
1>c:\users\owner\documents\visual studio 2010\projects\monopoly\monopoly\d3ddevice.h(11): error C2061: syntax error : identifier 'CXFileEntity'
1>c:\users\owner\documents\visual studio 2010\projects\monopoly\monopoly\window.h(20): error C2143: syntax error : missing ';' before '*'
1>c:\users\owner\documents\visual studio 2010\projects\monopoly\monopoly\window.h(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\owner\documents\visual studio 2010\projects\monopoly\monopoly\window.h(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
对于第一个错误,我在d3ddevice.h中包含Window.h(其中定义了窗口类)头文件,但它仍然说没有定义。
这是我的三个类CXFileEntity,Window,D3dDevice的源代码
d3ddevice.h
#ifndef D3dDevice_H_
#define D3dDevice_H_
#include "Window.h"
#include "XfileEntity.h"
class Window;
class D3dDevice : public Window
{
public:
D3dDevice(void);
~D3dDevice(void) { CleanUp(); };
void InitD3D();
void RenderFrame(CXFileEntity *m_entity);
void CleanUp(void);
void InitMatrices();
int Height; // BackBuffer Height
int Width; // BackBuffer Width
LPDIRECT3D9 d3d; // Pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev; // Pointer to the device class
};
#endif
cfileentity.h
#ifndef XFileEntity_H_
#define XFileEntity_H_
/*
This class represents an x file animation
It loads the .x file and carries out the animation update and rendering
*/
#include "Window.h"
#include "MeshStructures.h"
class Window;
class CXFileEntity : public Window
{
private:
LPDIRECT3DDEVICE9 m_d3dDevice; // note: a pointer copy (not a good idea but for simplicities sake)
// Direct3D objects required for animation
LPD3DXFRAME m_frameRoot;
LPD3DXANIMATIONCONTROLLER m_animController;
D3DXMESHCONTAINER_EXTENDED* m_firstMesh;
// Bone data
D3DXMATRIX *m_boneMatrices;
UINT m_maxBones;
// Animation variables
unsigned int m_currentAnimationSet;
unsigned int m_numAnimationSets;
unsigned int m_currentTrack;
float m_currentTime;
float m_speedAdjust;
// Bounding sphere (for camera placement)
D3DXVECTOR3 m_sphereCentre;
float m_sphereRadius;
std::string m_filename;
void UpdateFrameMatrices(const D3DXFRAME *frameBase, const D3DXMATRIX *parentMatrix);
void UpdateSkinnedMesh(const D3DXFRAME *frameBase);
void DrawFrame(LPD3DXFRAME frame) const;
void DrawMeshContainer(LPD3DXMESHCONTAINER meshContainerBase, LPD3DXFRAME frameBase) const;
void SetupBoneMatrices(D3DXFRAME_EXTENDED *pFrame/*, LPD3DXMATRIX pParentMatrix*/);
public:
CXFileEntity(LPDIRECT3DDEVICE9 d3dDevice);
~CXFileEntity(void);
D3DXMATRIX m_combinedMat;
void CreateRay();
bool Load(const std::string &filename);
CXFileEntity* LoadXFile(const std::string &filename,int startAnimation, CXFileEntity *m_entitys);
void FrameMove(float elapsedTime,const D3DXMATRIX *matWorld);
void Render() const;
void SetAnimationSet(unsigned int index);
void SetComb(LPDIRECT3DDEVICE9 d3dDevice, D3DXMATRIX world);
float m_fHitDist;
CXFileEntity *m_pChild;
CXFileEntity *m_pSibling;
void NextAnimation();
void AnimateFaster();
void AnimateSlower();
CXFileEntity *Pick(D3DXVECTOR3 *pvNear, D3DXVECTOR3 *pvDir, float maxDist, CXFileEntity *pObj);
BOOL m_bHit;
D3DXVECTOR3 GetInitialCameraPosition() const;
unsigned int GetCurrentAnimationSet() const {return m_currentAnimationSet;}
std::string GetAnimationSetName(unsigned int index);
std::string GetFilename() const {return m_filename;}
};
#endif
window.h中
#ifndef Window_H_
#define Window_H_
#include "D3dDevice.h"
#include "XfileEntity.h"
class Window
{
public:
Window(void);
~Window(void);
bool InitWindow(HINSTANCE hInstance, int nCmdShow);
void InitMesh();
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);
int Run( HACCEL hAccelTable );
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void Pick();
HWND hWnd;
D3dDevice d3dx;
CXFileEntity *m_entity;
private:
HINSTANCE hInst; // current instance // current window
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
};
#endif
更新
#ifndef Window_H_
#define Window_H_
class CXFileEntity;
class D3dDevice;
class Window
{
public:
Window(void);
~Window(void);
bool InitWindow(HINSTANCE hInstance, int nCmdShow);
void InitMesh();
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);
int Run( HACCEL hAccelTable );
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void Pick();
HWND hWnd;
D3dDevice d3dx;
CXFileEntity *m_entity;
private:
HINSTANCE hInst; // current instance // current window
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
};
#endif
答案 0 :(得分:3)
你的#include
中有循环依赖:d3ddevice.h包含Window.h,但Window.h又包含d3ddevice.h。
此外,您的D3dDevice
源自Window
,但也作为字段包含在Window
中。这样,每个Window
包含一个D3dDevice
作为字段,其中包含Window
作为其一部分,其中包含D3dDevice
作为字段,依此类推。因此,D3dDevice
所需的内存是无限的。
也许你想在D3dDevice
中只指向Window
?这样你就不需要在window.h中#include "D3dDevice.h"
,所以你可以在window.h中进行前向声明:class D3dDevice;
,从而打破循环依赖。
或者您可能不需要D3dDevice
来自Window
?