How can I cleanly specify which arguments I am passing and which remain default?

前端 未结 4 1833
醉酒成梦
醉酒成梦 2020-12-06 18:23

Asked because of this: Default argument in c++

Say I have a function such as this: void f(int p1=1, int p2=2, int p3=3, int p4=4);

And

4条回答
  •  抹茶落季
    2020-12-06 19:10

    Use the Named Parameters Idiom (→ FAQ link).

    The Boost.Parameters library (→ link) can also solve this task, but paid for by code verbosity and greatly reduced clarity. It's also deficient in handling constructors. And it requires having the Boost library installed, of course.

提交回复
热议问题