arrdy
arrdy

Reputation: 63

'optional': is not a member of 'std' in Visual Studio

The code I am writing is throwing this error:

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

I understand that the file <optional> is located in MSVC/tools and this external dependencies section is usually populated by Intellisense, but the file appears not to be included even though I confirmed that the file does indeed exist and I have #include <optional>.

What is the best way to close the gap here?

Is there a way to tell Visual Studio to include all the MSVC tools?

Code snippet from header:

#pragma once

#include Examples.h

#include <optional>
#include <vector>

namespace Samples

Code snippet from cpp:

#include 'Examples.h'

std::optional<Samples::Matrix> Samples::TestFunction()

Upvotes: 4

Views: 10220

Answers (1)

Casey
Casey

Reputation: 10936

You must have your C++ Language Standard option in Project Settings set to C++17 or later:

  1. Right-Click on the project in the Solution Explorer
  2. Select Properties
  3. Under Configuration Properties > General > C++ Language Standard
  4. Select ISO C++17 Standard (/std:c++17) or Preview Latest (/std:latest)
  5. Future readers: ISO C++20 Standard (/std:c++20) is also an option.
  6. Click OK
  7. Save All to save the changes to the project.

Upvotes: 12

Related Questions