【问题标题】:C++ "overloading" second default function argument [duplicate]C ++“重载”第二个默认函数参数[重复]
【发布时间】:2017-01-16 18:00:02
【问题描述】:

有没有办法像在 Python 中一样选择在 c++ 中覆盖哪些函数参数?

示例代码:

#include <iostream>

using namespace std;

void test(int a=1, int b=1) {}

int main()
{
    test(b=2);
    cout << "kkk" << endl;
}

【问题讨论】:

    标签: c++ default-arguments


    【解决方案1】:

    不,没有。在 C++ 中,您始终需要按照参数在函数声明中出现的顺序提供参数。

    在许多情况下存在的解决方法是为该函数提供重载。

    【讨论】:

    • 啊,当然谢谢你,这会起作用的,非常感谢
    猜你喜欢
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多