• 【c++ primer, 5e】函数匹配


    练习

    6.49

    候选函数:与所调用的函数的名字相同的函数的集合。

    可行函数:给候选函数加上参数数量、参数类型的约束所得到的函数的集合。

    6.50

    a 3、4可行,二义匹配

    b 2、4可行,2是最佳匹配

    c 3、4可行,3是最佳匹配

    d 3、4可行,4是最佳匹配

    6.51

    测试代码:

    #include <iostream>
    using namespace std;
    void f()
    {
        cout << "f1" << endl;
    }
    void f(int)
    {
        cout << "f2" << endl;
    }
    void f(int, int)
    {
        cout << "f3" << endl;
    }
    void f(double, double = 3.14)
    {
        cout << "f4" << endl;
    }
    int main()
    {
        // f(2.56, 42);  error: call of overloaded 'f(double, int)' is ambiguous
        f(42);
        f(42, 0);
        f(2.56, 3.14);
        return 0;
    }

    输出结果:

    $ a
    f2
    f3
    f4

    【实参类型转换】

    练习

    6.52

    a 3

    b 4

    6.53

    c 是不合法的,详细参考p208。

  • 相关阅读:
    Canvas 绘画
    h5内容初探
    border&background1
    css3选择器补充
    bootstrap
    css3文本和颜色
    css3边框与背景
    css3选择器
    jQuery之dom操作(取赋值方法)
    push.default
  • 原文地址:https://www.cnblogs.com/xkxf/p/6658221.html
Copyright © 2020-2023  润新知