开发者

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.

here is my source code for the three class 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_numAnimationS开发者_StackOverflow中文版ets;
 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 #includes: d3ddevice.h includes Window.h, but Window.h in turn includes d3ddevice.h.

Moreover, your D3dDevice is derived from Window, but is contained in Window as a field as well. 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. As a result, the needed memory for D3dDevice is infinite.

Perhaps you want to have only a pointer to D3dDevice in Window? 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;, thus breaking the circular dependency.

Or maybe you don't need your D3dDevice to be derived from Window?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜