SpriteBatch 和 SpriteFont (DirectXTK) 抛出错误(预期为 unqualified-id)

SpriteBatch and SpriteFont (DirectXTK) throw an error (expected unqualified-id)

我正在使用链接到 MSVCclang++

我编译了着色器 (DirectXTK\Shaders) 并在我的源代码中包含了 SpriteBatchSpriteFont

如果我只包含头文件 (.h),我会得到链接错误;如果我包含源文件(.cpp;有或没有 .h),我得到这个:

SpriteBatch.cpp:532:27: error: expected unqualified-id
    size_t newSize = std::max(InitialQueueSize, mSpriteQueueArraySize * 2);
                          ^
C:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared\minwindef.h:193:29: note: expanded from macro 'max'
#define max(a,b)            (((a) > (b)) ? (a) : (b))

我试图在 DirectXTK 的 GitHub 问题页面、本网站和网络上找到解决方案,但没有找到任何有用的东西。

Windows headers 定义了一个 'min' 和 'max' 宏,它与来自 [=13= 的 std::min/std::max 交互不佳].

在我所有的模板和测试中,我在使用 Windows.h 之前定义 NOMINMAX 以避免这个问题。这通常是一种更好的做法。如果在执行此操作时仍需要使用宏形式,则可以使用 __min/_max.

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#define NODRAWTEXT
#define NOGDI
#define NOBITMAP
#define NOMCX
#define NOSERVICE
#define NOHELP

#include <Windows.h>

this other thread and this blog post