0

In Python you can define a function with default parameters like this:

def foo (a = 0, b = 0, c = 0):
...

and then call that function with specific parameters, eg.

foo(c = 1)

which leaves remaining variables default. Is there a way to do similar thing in C++ on complex function like this one?

void foo(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0);

Calling it foo(c = 1) or foo(int c = 1) causes errors.

EDIT: So I understand that it can't be done this way and it was answered in this question:

Why C++ doesn't support named parameter

Is there any other way for passing a specific parameter though? This question is not a duplicate of the question mentioned above as my question's intention is to find out if there is any way to speed up passing parameters into function like this and the Python example (named parameters) is just - as I said - an example of doing that.

EDIT2: I found a question which better describes the problem and mine could be a duplicate of it:

Specifying default parameter when calling C++ function

Elgirhath
  • 409
  • 1
  • 7
  • 15
  • I think what you're referring to is "named parameters". I wouldn't be surprised if C++ mangles parameter names, so I don't think this would be possible. – Carcigenicate Jul 19 '18 at 22:11
  • You can actually with a lot of effort implement something like this in C++: you have to define special argument types which can be constructed from expressions `argument=value`, and then take the lot of them via variadic template ... – Walter Jul 19 '18 at 23:09

0 Answers0