命名空间 std:: 不包含可选

namespace std:: does not contain optional

我正在学习 Vulkan 教程 https://vulkan-tutorial.com/

#define GLFW_INCLUE_VULKAN
#include<GLFW/glfw3.h>
#include<optional>

struct s {
    std::optional<uint32_t> num;//Intellisense Error
};

int main() {
    return 5;
}

我从一个空项目开始,添加了包含和库; 我可以编译 运行 而不包含 std::optional.

当我使用 std::optional 我得到 c2039 "optional is not a member of std"

我 运行宁 Windows 10 岁,VisualStudio 2019

这是怎么回事?

谢谢。

std::optional 需要 C++17。

生活在Godbolt

您可以在 MSVC 上使用 /std:c++17 标志,在 gcc/clang 上使用 -std=c++17