#include <iostream>
#include <variant>
using namespace std;
int main()
{
variant<int, float> var{0.23};
if(holds_alternative<float>(var)){
if(var.index() == 1){
cout << get<float>(var) << endl;
}
}
return 0;
}
The initialization should work but instead it gives the following error:
main.cpp: In function 'int main()': main.cpp:7:33: error: no matching function for call to 'std::variant<int, float>::variant()'
I'm not sure if I made a mistake in the code.