Here's a nonsensical but demonstrative example program:
#include <string> #include <iostream> auto polyret() { struct proof_of_concept { operator int() { return 4; } operator double() { return 1.5; } operator std::string() { return "I'm a string!"; } }; return proof_of_concept(); } int main() { int a = polyret(); double b = polyret(); std::string c = polyret(); std::cout << "int: " << a << std::endl; //prints 4 std::cout << "double: " << b << std::endl; //prints 1.5 std::cout << "string: " << c << std::endl; //prints "I'm a string!" }
Here's a nonsensical but demonstrative example program: