如何取消初始化std :: experimental :: optional?
std::experimental::optional<std::string> name;
name = std::string("hello"); //how to uninitialize name?
if(name)
{
std::cout << "name is set" << std::endl;
}
else
{
std::cout << "name is not set" << std::endl;
}
如何点击其他分支?
答案 0 :(得分:3)
name = std::experimental::nullopt;
std :: experimental :: nullopt是std :: experimental :: nullopt_t类型的常量,用于表示具有未初始化状态的可选类型。