Really impossible to use return type overloading?

前端 未结 7 1353
梦如初夏
梦如初夏 2020-11-30 11:20

I made a small DLL in MSIL with two methods:

float AddNumbers(int, int)
int AddNumbers(int, int)

As some of you might know, MSIL allows you

7条回答
  •  天涯浪人
    2020-11-30 12:07

    The problem is that there is an automatic conversion from int to float so it really doesn't know what you intended. Did you intend to call the method that takes two ints and returns an int, then convert it to float or did you intend to call the method that takes two ints and returns a float? Better to have a compiler error than to make the wrong choice and not let you know until your application breaks.

提交回复
热议问题