Search code examples
c++stdoptional

namespace std:: does not contain optional


I am doing the Vulkan Tutorial 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;
}

I started with an empty project and added includes and libraries; I can compile and run without including std::optional.

When I use std::optional I get c2039 "optional is not a member of std"

I am running Windows 10, and VisualStudio 2019.

What is going on here?


Solution

  • std::optional requires C++17.

    Live on Godbolt.

    you can use /std:c++17 flag on MSVC and -std=c++17 on gcc/clang.