Initially seems like very trivial problem.
i have input: string a, string b.
b only takes two values, “string” and “int”.
i want to declare a new variable var0 with a type that corresponds to b.
how to implement the logic.
i thought this function would work but it wont.
auto varx(std::string a, std::string b){
if(b == "int") return std::stoi(a);
return a;
}
e.g. auto var0 = varx(“43”, “int”); should set var0 as int var0 = 43;
I have seen union or variant in discussions but not sure how to implement.
Aaditya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.