_D3DVECTOR' : "结构"类型重新定义

_D3DVECTOR' : 'struct' type redefinition

本文关键字:新定义 定义 类型 结构 D3DVECTOR      更新时间:2023-10-16

出现此错误。怎么了?谢谢你的回复

Error 36 Error C2011: ' _d3vector ': 'struct' type redefinition Renderer.h

错误37错误C2504: ' _d3vector ':基类未定义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 

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

例如,下面的代码将生成两个错误,"hello"answers"world"。

typedef struct _D3DVECTOR {
    float x;
    float y;
    float z;
} D3DVECTOR;
#ifndef _D3DVECTOR
#error hello
#endif
#ifndef D3DVECTOR
#error world
#endif