[英]c++ inherited class 'Window' : base class undefined
when i inherited classes i get these errors messages. 当我继承类时,会收到这些错误消息。
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
for the first error i'm including the Window.h(where window class is defined) header file in d3ddevice.h but it still say that is not defined. 对于第一个错误,我在d3ddevice.h中包含Window.h(定义了窗口类的位置)头文件,但仍说未定义。
here is my source code for the three class CXFileEntity, Window, D3dDevice 这是我的三个类CXFileEntity,Window,D3dDevice的源代码
d3ddevice.h 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 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
UPDATE 更新
#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
You've got circular dependencies in your #include
s: d3ddevice.h includes Window.h, but Window.h in turn includes d3ddevice.h. 您的
#include
包含循环依赖项:d3ddevice.h包含Window.h,而Window.h反过来又包含d3ddevice.h。
Moreover, your D3dDevice
is derived from Window
, but is contained in Window
as a field as well. 此外,您的
D3dDevice
派生自Window
,但也作为字段包含在Window
中。 This way every Window
contains a D3dDevice
as a field, which contains Window
as its part, which contains D3dDevice
as a field and so on. 这样,每个
Window
将D3dDevice
作为字段包含,将Window
作为其一部分,将D3dDevice
作为字段包含,依此类推。 As a result, the needed memory for D3dDevice
is infinite. 结果,
D3dDevice
所需的内存是无限的。
Perhaps you want to have only a pointer to D3dDevice
in Window
? 也许您只希望
Window
有一个指向D3dDevice
的指针? This way you don't need to #include "D3dDevice.h"
in window.h, so you can just make a forward declaration in window.h: class D3dDevice;
这样,您无需在window.h中
#include "D3dDevice.h"
,因此您只需在window.h中进行前向声明即可: class D3dDevice;
, thus breaking the circular dependency. ,从而打破了循环依赖。
Or maybe you don't need your D3dDevice
to be derived from Window
? 或者,也许您不需要从
Window
派生D3dDevice
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.