我對編譯器無法識別我的類感到困惑。所以我只是要告訴你我的代碼,並讓你們決定。我的錯誤是這樣標題混淆。編譯器無法識別數據類型
error C2653: 'RenderEngine' : is not a class or namespace name
,它的指向此行
std::vector<RenderEngine::rDefaultVertex> m_verts;
這裏是rModel代碼,在其全部。它包含變量。持有它的階級進一步下降。
#ifndef _MODEL_H
#define _MODEL_H
#include "stdafx.h"
#include <vector>
#include <string>
//#include "RenderEngine.h"
#include "rTri.h"
class rModel {
public:
typedef tri<WORD> sTri;
std::vector<sTri> m_tris;
std::vector<RenderEngine::rDefaultVertex> m_verts;
std::wstring m_name;
ID3D10Buffer *m_pVertexBuffer;
ID3D10Buffer *m_pIndexBuffer;
rModel(const TCHAR *filename);
rModel(const TCHAR *name, int nVerts, int nTris);
~rModel();
float GenRadius();
void Scale(float amt);
void Draw();
//------------------------------------ Access functions.
int NumVerts(){ return m_verts.size(); }
int NumTris(){ return m_tris.size(); }
const TCHAR *Name(){ return m_name.c_str(); }
RenderEngine::cDefaultVertex *VertData(){ return &m_verts[0]; }
sTri *TriData(){ return &m_tris[0]; }
};
#endif
在代碼的最頂端有一個頭文件
#include "stdafx.h"
包括該
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include "resource.h"
#include "d3d10.h"
#include "d3dx10.h"
#include "dinput.h"
#include "RenderEngine.h"
#include "rModel.h"
// TODO: reference additional headers your program requires here
,你可以看到,RenderEngine.h來rModel.h
前#include "RenderEngine.h"
#include "rModel.h"
根據我的知識,它應該認識到它。但另一方面,我不擅長組織標題。這裏是我的RenderEngine聲明。
#pragma once
#include "stdafx.h"
#define MAX_LOADSTRING 100
#define MAX_LIGHTS 10
class RenderEngine {
public:
class rDefaultVertex
{
public:
D3DXVECTOR3 m_vPosition;
D3DXVECTOR3 m_vNormal;
D3DXCOLOR m_vColor;
D3DXVECTOR2 m_TexCoords;
};
class rLight
{
public:
rLight()
{
}
D3DXCOLOR m_vColor;
D3DXVECTOR3 m_vDirection;
};
static HINSTANCE m_hInst;
HWND m_hWnd;
int m_nCmdShow;
TCHAR m_szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR m_szWindowClass[MAX_LOADSTRING]; // the main window class name
void DrawTextString(int x, int y, D3DXCOLOR color, const TCHAR *strOutput);
//static functions
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
bool InitWindow();
bool InitDirectX();
bool InitInstance();
int Run();
void ShutDown();
void AddLight(D3DCOLOR color, D3DXVECTOR3 pos);
RenderEngine()
{
m_screenRect.right = 800;
m_screenRect.bottom = 600;
m_iNumLights = 0;
}
protected:
RECT m_screenRect;
//direct3d Members
ID3D10Device *m_pDevice; // The IDirect3DDevice10
// interface
ID3D10Texture2D *m_pBackBuffer; // Pointer to the back buffer
ID3D10RenderTargetView *m_pRenderTargetView; // Pointer to render target view
IDXGISwapChain *m_pSwapChain; // Pointer to the swap chain
RECT m_rcScreenRect; // The dimensions of the screen
ID3D10Texture2D *m_pDepthStencilBuffer;
ID3D10DepthStencilState *m_pDepthStencilState;
ID3D10DepthStencilView *m_pDepthStencilView;
//transformation matrixs system
D3DXMATRIX m_mtxWorld;
D3DXMATRIX m_mtxView;
D3DXMATRIX m_mtxProj;
//pointers to shaders matrix varibles
ID3D10EffectMatrixVariable* m_pmtxWorldVar;
ID3D10EffectMatrixVariable* m_pmtxViewVar;
ID3D10EffectMatrixVariable* m_pmtxProjVar;
//Application Lights
rLight m_aLights[MAX_LIGHTS]; // Light array
int m_iNumLights; // Number of active lights
//light pointers from shader
ID3D10EffectVectorVariable* m_pLightDirVar;
ID3D10EffectVectorVariable* m_pLightColorVar;
ID3D10EffectVectorVariable* m_pNumLightsVar;
//Effect members
ID3D10Effect *m_pDefaultEffect;
ID3D10EffectTechnique *m_pDefaultTechnique;
ID3D10InputLayout* m_pDefaultInputLayout;
ID3DX10Font *m_pFont; // The font used for rendering text
// Sprites used to hold font characters
ID3DX10Sprite *m_pFontSprite;
ATOM RegisterEngineClass();
void DoFrame(float);
bool LoadEffects();
void UpdateMatrices();
void UpdateLights();
};
這些類的類
class rDefaultVertex
{
public:
D3DXVECTOR3 m_vPosition;
D3DXVECTOR3 m_vNormal;
D3DXCOLOR m_vColor;
D3DXVECTOR2 m_TexCoords;
};
class rLight
{
public:
rLight()
{
}
D3DXCOLOR m_vColor;
D3DXVECTOR3 m_vDirection;
};
不知道如果那是很好的做法中定義,但是我只是按章辦事去。最後,我只需要一個很好的方法來組織它,以便rModel識別RenderEngine。如果可能的話,反過來。
[編輯]
我可以從字面上只是指向渲染引擎類,它仍然不會承認
#ifndef _MODEL_H
#define _MODEL_H
//#include "stdafx.h"
#include <vector>
#include <string>
#include "RenderEngine.h" //<-------pointing to render engine. still does not recognize.
#include "rTri.h"
class rModel {
public:
typedef tri<WORD> sTri;
std::vector<sTri> m_tris;
std::vector<RenderEngine::rDefaultVertex> m_verts;
std::wstring m_name;
ID3D10Buffer *m_pVertexBuffer;
ID3D10Buffer *m_pIndexBuffer;
rModel(const TCHAR *filename);
rModel(const TCHAR *name, int nVerts, int nTris);
~rModel();
float GenRadius();
void Scale(float amt);
void Draw();
//------------------------------------ Access functions.
int NumVerts(){ return m_verts.size(); }
int NumTris(){ return m_tris.size(); }
const TCHAR *Name(){ return m_name.c_str(); }
RenderEngine::cDefaultVertex *VertData(){ return &m_verts[0]; }
sTri *TriData(){ return &m_tris[0]; }
};
#endif
好了,我的應用程序並不那麼複雜。它只包含2個班級。 RenderEngine(帶有rLight和rDefaultVertex)和rMdodel。這就對了。當然,還有WinMain文檔,但也有stdafx頭文件。簡而言之,我所有的文檔都有一個stdafx頭文件。有沒有直接的方式來看待這一點,並說什麼是對的,什麼是錯的? – numerical25 2010-05-24 13:51:56
啓動一個'Empty Project',添加所有的頭文件並去除預編譯頭文件'stdafx.h'。執行此操作後,解決文件問題將變成一項簡單的任務。 – 2010-05-24 14:05:12