Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6330947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:57:54+00:00 2026-05-24T17:57:54+00:00

Suppose I have class A,B,C; const A a_def; const B b_def; const C c_def;

  • 0

Suppose I have

class A,B,C;

const A a_def;
const B b_def;
const C c_def;

void f(A a=a_def, B b=b_def, C c=c_def);

This does, if I want to use the default parameters, only allow me to omit either just c, or b and c, or all three of them – but not just a or b alone. However, as the argument types cannot be mixed up, it would be completely unabiguous to call f(A(), C()), (or in fact f(B(), C(), A()): the order of arguments is arbitrary and actually meaningless).

To enable these alternative ways of calling the function, I now tend to overload every permutation manually

void f(A a, C c,       B b=b_def) { f(a,b,c); }
void f(B b, A a=a_def, C c=c_def) { f(a,b,c); }
void f(B b, C c,       A a=a_def) { f(a,b,c); }
void f(C c, A a=a_def, B b=b_def) { f(a,b,c); }
void f(C c, B b,       A a=a_def) { f(a,b,c); }

which is acceptable for just three parameters (3!=6 permutations) but gets tedious at four (4!=24 permutations) and out of bounds at five parameters (5!=120 permutations).

Is there any way to get this functionality automatically, without actually having to do all the overloads, for instance by means of variable argument lists or some kind of template metaprogramming?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:57:54+00:00Added an answer on May 24, 2026 at 5:57 pm

    Look into the Boost.Parameters Library. It uses some template heavy lifting to get it to work. http://www.boost.org/doc/libs/1_37_0/libs/parameter/doc/html/index.html

    It works basically by making your ‘named’ parameters into types that can be created, and assigned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a class class person { char* name; public: void setname(const char*);
Suppose I have this class: class foo { public: foo() { } foo(const std::string&
Suppose I have class A { public: void print(){cout<<A; }}; class B: public A
Suppose I have a class that processes some data: class SomeClass { public: void
Suppose I have an autolocker class which looks something like this: template <T> class
Suppose I have two versions of operator-> (overloaded on const) in a base class.
Suppose I have a class like this: class MyClass { private: vector<MyOtherClass> myMember; public:
So suppose I have a class like this one: class Point { private: int
Suppose i have declared subscript operators in a class char& operator[] (int index); const
Suppose I have a class that I want to make sure my compiler (GCC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.