std::optional?

a_unique_name 401 Reputation points
2023-01-12T01:13:30.1833333+00:00

Hi Folks:

Developing with Visual Studio, updated today to version 17.4.4.

I'm starting the Vulkan tutorial and I'm stuck at:

https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Physical_devices_and_queue_families

struct QueueFamilyIndices {

Apparently the code block will only display one line so I'll complain again about how much I hate this forum software, I love and appreciate you guys and gals, and how much I prefer the one that was used by MSDN.

And here's the code I can't display in the code block:

**struct QueueFamilyIndices {
std::optional<uint32_t> graphicsFamily;

bool isComplete() {  
    return graphicsFamily.has_value();  
}  

};**

The errors are on the std::optional statement.

error C2039: 'optional': is not a member of 'std'

error C7568: argument list missing after assumed function template 'optional'

Here's Project Properties -> C++ -> Language:
language_property

I've tried different C++ Language Standard, Conformance mode and even C Language Standard, with no effect.

https://en.cppreference.com/w/cpp/utility/optional shows a c++17 compliant compiler should be able to handle std::optional.

What am I doing wrong?

Thanks

Larry

Developer technologies | C++
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. cheong00 3,486 Reputation points Volunteer Moderator
    2023-01-12T12:00:18.2366667+00:00

    Make sure you add the following at the top of your code:

    #include <optional>
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.