大佬教程收集整理的这篇文章主要介绍了c – 重载函数中数据类型的优先级如何?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <iostream> using namespace std; void MyFunc (int i) { cout << "int" << endl; } void MyFunc (double i) { cout << "double" << endl; } void MyFunc (float i) { cout << "float" << endl; } int main () { MyFunc(1); float x = 1.0; MyFunc(X); MyFunc(1.0); MyFunc(15.0); return 0; }
输出:
int float double double
程序如何决定调用float还是double?
这解释了观察到的重载分辨率:
MyFunc(X);//calls MyFunc(float) since x is a float MyFunc(1.0);//calls MyFunc(doublE) since 1.0 is a double MyFunc(15.0);//calls MyFunc(doublE) since 15.0 is a double
类似的推理也适用于integer literals – 1是int类型的文字.
以上是大佬教程为你收集整理的c – 重载函数中数据类型的优先级如何?全部内容,希望文章能够帮你解决c – 重载函数中数据类型的优先级如何?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。