IntelliSense:标识符“XMFLOAT4”未定义

0 c c++ directx intellisense direct3d

    #ifndef RENDERER_H
    #define RENDERER_H

    #pragma once

    #include "Font.h"
    #include "Color.h"

    #undef CreateFont

struct Vertex_t {
    XMFLOAT4 xyzrhw;
    D3DCOLOR color;

    enum {
        FVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE
    };
};
Run Code Online (Sandbox Code Playgroud)

当我尝试编译时出现此错误:

IntelliSense:标识符“XMFLOAT4”未定义。

我该如何解决?

Chu*_*urn 5

从您的代码中不清楚您在哪里包含<DirectXMath.h>,所以我假设它位于 Font.h 或 Color.h 中的某个位置。

DirectXMath 使用 C++ 命名空间DirectX,因此您应该使用:

struct Vertex_t {
    DirectX::XMFLOAT4 xyzrhw;
    D3DCOLOR color;

    enum {
        FVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE
    };
};
Run Code Online (Sandbox Code Playgroud)

C++ 编码建议是避免将using namespace语句放入标头中,仅将它们保留在 .cpp 文件本地。