What does “Unable to overload functions other than return type” mean?

I have this code:

In the title:

... int32_t round(float v); ... 

and in the source

 ... int32_t round(float v) { int32_t t = (int32_t)std::floor(v); if((v - t) > 0.5) return t + 1; return t; } ... 

I looked here on this site, but the examples seem to me too complicated.

I am learning C ++, so if someone can explain to me what the error means and why this happens, I would be grateful.

+5
source share
1 answer

Function overloading means that there are several methods with the same name.

Now, to allow the correct overloaded method, the compiler looks for the method name and arguments, but NO when the value is returned. That means if you have

 int round(float something) { ... } float round(float something) { ... } 

Then the compiler will not be able to distinguish them and find out which one you want to call at the dial-peer. So in your case, this means that there is another round method that accepts a float .

+13
source

Source: https://habr.com/ru/post/1213004/


All Articles