I want to create function that returns std::variant value according to holds_alternative. If there is an A* type in the DDD, return A* type value else If there is an B* type in the DDD, retrun B* type value. But if there is nothing in DDD, how does this function return nullptr?? please help.. Thanks!
using vvv = std::variant<std::monostate, A*, B*> ;
vvv func () {
vvv DDD;
DDD = new A;
if (std::holds_alternative<A*>) {
return std::get<A*> DDD;
} else if (std::holds_alternative<B*>) {
return std::get<B*> DDD;
} else {
return nullptr; <= error!!!
}
}
========== build error message =========
No viable conversion from returned value of type nullptr_t to function return type vvv (aka variant<std::monostate, A*, B*> )