C ++在函数中仅使用一个默认参数 [英] C++ using only one default argument in function

查看:38
本文介绍了C ++在函数中仅使用一个默认参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么只能使用第三个参数(第一个和第二个参数必须是默认值)?

How can i use only 3rd argument (first and second arguments must be default)?

赞:

double func(const double a = 5, const double b = 6, const double c = 7);

int main()
{
    cout << "A = " << func(10) << endl << endl; //if i do like this, i'm using first argument, but not 3rd.
}

推荐答案

C ++当前不支持您要执行的操作.但是,有一些解决方法.您可以使用命名参数成语或boost的Paremeter库.

C++ doesn't support what you want to do currently. However, there are ways around it. You can use the Named Parameter Idiom or boost's Paremeter library.

我推荐前者.更清晰,更容易调试等...

I recommend the former. It's clearer, easier to debug, etc...

这篇关于C ++在函数中仅使用一个默认参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆