重载函数的调用匹配,依次按照下列规则来判断:

         精确匹配:参数匹配而不做转换,或者只是做微不足道的转换,如数组名到指针、函数名到指向函数的指针、T到const T;

         提升匹配:即整数提升(如bool到int、char到int、short到int),float到double;

         使用标准转换匹配:如int到double、double到int、double到long double、Derived*到Base*、T*到void*、int到unsigned int;

         使用用户自定义匹配;

         使用省略号匹配:类似于printf中省略号参数。

假如运行环境int类型4bytes,short类型2bytes,long类型8bytes,存在代码:
    unsigned short x = 65530;
    int a = myfunc( x, 20.0 );
会优先匹配以下哪一个重载函数?
A. int myfunc( double, double ) 
B. int myfunc( short, double )
C. double myfunc( int, float )
D. double myfunc( int, double)

答案为D!

相关文章:

  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
猜你喜欢
  • 2021-08-06
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2023-01-13
  • 2021-05-26
  • 2021-09-30
相关资源
相似解决方案