You can emulate that by returning a type with two conversion operators to the types you want.

On Tue, Apr 5, 2022 at 11:59 AM PaulIRL via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
Hi, I'm currently learning C++ and at first I wondered why we can have 2 functions with the same name and different parameters but, not with the same name, same parameters and a different return type, but probably this is because the c++ compiler wouldn't know which function to call, however, I think that a good solution is forcing the user (programmer) to cast the output, and that way the compiler will know which function to call.
Example
int RandomNumber() {
    return 7; //for simplicity
}

float RandomNumber() {
    return 5.2 //for simplicity again
}

one could do

std::cout<<(float)RandomNumber()<<std::endl; //prints 5.2\n

however
std::cout<<RandomNumber()<<std::endl;
would throw a compiler error

this would also work as expected
std::cout<<(int)(float)RandomNumber()<<std::endl; //prints 5\n

- Paul Abrudan

Trimis cu ProtonMail e-mail securizat.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals