_D3DVECTOR' :' struct'类型重新定义

时间:2014-05-20 23:39:17

标签: c++

有这个错误。怎么了?感谢您的回复

错误36错误C2011:' _D3DVECTOR' :' struct'类型redefinition \ Renderer.h

错误37错误C2504:' _D3DVECTOR' :基类undefined \ Renderer.h

这是Render.h

#include <D3D11.h> 
#include <d3dx11.h> 
#include <DXErr.h> 
#include <D3DX11async.h> 
#include <D3Dcompiler.h> 
#include <D3dx11effect.h> 
#include <D3D11Shader.h> 
#include "FW1FontWrapper.h" 

#ifndef _D3DVECTOR 
ERROR here> typedef struct _D3DVECTOR {
    float x;
    float y;
    float z;
} D3DVECTOR;
#endif 

#ifndef D3DXVECTOR3 
typedef struct D3DXVECTOR3 : public D3DVECTOR
ERROR here> {
public:
    D3DXVECTOR3() {};
    D3DXVECTOR3(CONST FLOAT *);
    D3DXVECTOR3(CONST D3DVECTOR&);
    D3DXVECTOR3(CONST D3DXFLOAT16 *);
    D3DXVECTOR3(FLOAT x, FLOAT y, FLOAT z);

    // casting 
    operator FLOAT* ();
    operator CONST FLOAT* () const;

    // assignment operators 
    D3DXVECTOR3& operator += (CONST D3DXVECTOR3&);
    D3DXVECTOR3& operator -= (CONST D3DXVECTOR3&);
    D3DXVECTOR3& operator *= (FLOAT);
    D3DXVECTOR3& operator /= (FLOAT);

    // unary operators 
    D3DXVECTOR3 operator + () const;
    D3DXVECTOR3 operator - () const;

    // binary operators 
    D3DXVECTOR3 operator + (CONST D3DXVECTOR3&) const;
    D3DXVECTOR3 operator - (CONST D3DXVECTOR3&) const;
    D3DXVECTOR3 operator * (FLOAT) const;
    D3DXVECTOR3 operator / (FLOAT) const;

    friend D3DXVECTOR3 operator * (FLOAT, CONST struct D3DXVECTOR3&);

    BOOL operator == (CONST D3DXVECTOR3&) const;
    BOOL operator != (CONST D3DXVECTOR3&) const;

} D3DXVECTOR3, *LPD3DXVECTOR3;
#endif 

1 个答案:

答案 0 :(得分:1)

这里的问题是#ifndef不能用于检测结构标签或typedef。 #ifndef仅用于确定是否存在宏(使用#define声明)。

例如,以下代码将生成两个错误,“hello”和“world”。

typedef struct _D3DVECTOR {
    float x;
    float y;
    float z;
} D3DVECTOR;

#ifndef _D3DVECTOR
#error hello
#endif

#ifndef D3DVECTOR
#error world
#endif
相关问题