How can I have a C++ function that returns different types depending on what the caller wants?
This is not allowed in C++. The return type of a function cannot be overloaded.
But Kenny Kerr taught me how to fake it. What you do is return an object that doesn’t yet know whether it’s a widget or doodad.