Is it possible to do function overloading with different return type?

For example:

void myfunc(double x, double y);
double myfunc(bool x);

Recommended Answers

All 2 Replies

Yes, but not only return types. Your example is fine.

>>Is it possible to do function overloading with different return type?

No its not consider this situation :

void what(){ return /* nothing */ ;  }
bool what(){ return true; }
int main(){
 what(); //which function does this call ?
}

As you see, overloading functions with different return types makes
function calls ambiguous.

However, what you have written here :

void myfunc(double x, double y);
double myfunc(bool x);

is fine because myfunc(...) does not have the same parameters.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.