Reputation: 357
This code does not compile with the command g++ -std=c++17 main.cpp
#include <iostream>
#include <experimental/optional>
int main()
{
std::optional<int> x;
std::cout << "Hello World";
return 0;
}
The Errors are the following:
Is there a way to get this code to compile?
Upvotes: 1
Views: 1650
Reputation: 58007
The <experimental/optional>
header doesn't define std::optional
but rather std::experimental::optional
. To get std::optional
, which is a (non-experimental) part of the C++17 standard, you should just #include <optional>
.
Upvotes: 9