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.
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

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.