【发布时间】:2014-08-16 01:13:33
【问题描述】:
我的项目有两种方法,定义如下:
void Person(int ID, double height = 0.0, string team = "Knights")
{
//my codes
}
void Person(int ID, double height = 0.0, string team = "Knights", int age = 30)
{
//my codes
}
这是我调用方法的地方:
Person(1, 2.5, "Dark Ghost"); //calls first method
我在构建项目时没有收到任何错误但是我很困惑为什么上面调用第一个方法?
和:
Person(1, 46.5); //compiler error.
【问题讨论】:
-
那你为什么不测试它会被调用?
-
拥有两个有什么意义?为什么不直接删除第一个并始终使用第二个?