0
Is there a function that can return both an integer and a character?
3 Answers
+ 4
Pretty sure you can do this using a vector. Also, if the char and int are related to one another (the same value, just different number/ascii bases), you could just return one of them, duplicate the returned value, and then convert the duplicate.
+ 1
It really depends on what you mean:
If you want to return both int and char at the same type, you can't do it directly, but you can return something like pair and store values in it (but you will have to treat it differently)
If you want to return either int or char depending on arguments, you can do that with overloading.
If you want to return either int or char, but function to have same parameters, then you can't. You could do it in dynamically typed languages (but you really shouldn't)
0
you could define a struct that contains a char and an int and use that struct as return type or return a std::tuple<char,int>
http://en.cppreference.com/w/cpp/utility/tuple
even fancier:
return std::tuple<std::optional<char>,std::optional<int>>
http://en.cppreference.com/w/cpp/utility/optional