我是,头部防护解决重新定义的问题的印象。我收到的链接器错误表明在.obj文件中有重新定义。这是我包含的标题,问题在于重新定义所有全局声明。部首后卫/翻译单元问题
#ifndef DIRECT3D_H
#define DIRECT3D_H
// global declarations
ID3D10Device* device;
ID3D10Buffer* pBuffer;
ID3D10Buffer* iBuffer; // the pointer to the index buffer
ID3D10RenderTargetView* rtv; // the pointer to the render target view
ID3D10DepthStencilView* dsv; // the pointer to the depth stencil view
IDXGISwapChain* swapchain; // the pointer to the swap chain class
ID3D10Effect* pEffect;
ID3D10EffectTechnique* pTechnique;
ID3D10EffectPass* pPass;
ID3D10InputLayout* pVertexLayout;
ID3D10EffectMatrixVariable* pTransform; // the pointer to the effect variable interface
D3D10_PASS_DESC PassDesc;
// function prototypes
void initD3D(HWND hWnd);
void render_frame();
void init_pipeline();
void cleanD3D();
void Init();
#endif
说这个头被称为3DClass.h。它包含在3DClass.cpp中。它也被包含在另一个文件中 - 一个主要的游戏循环。现在,我意识到可能存在与头文件时,有多个翻译单位的问题,但我不明白为什么这会无法正常工作,我只是其中一个文件头,并在相应的源文件。这不应该罚款吗?
你可能想阅读[这个答案](http://stackoverflow.com/questions/6923961/source-file-and-header-in-c/6924146#6924146)。 – sbi
哇,所有的全局变量是什么? –