I realize standard C++ only picks functions by argument type, not return type. I.e I can do something like:
void func(int);
void func(double);
but not
double func();
int func();
Where in the former, it’s clear, in the latter, it’s ambigious. Are there any extensions that lets me tell C++ to pick which function to use also by return type?
Thanks!
You cannot have two functions in the same scope that have the same name and signature (ie. argument types). Yet you can create a function that will behave differently depending on what variable you assign the result to, as in:
by making
f()return a proxy with an overloaded cast operator.See http://ideone.com/ehUM1
Not that this particular use case (returning a different number) is useful, but there
are uses for this idiom.