in C++ by (14.9k points)
0 like 0 dislike

I want to set function with static class object parameter set as default. How I can to set default value for function/method parameter as static created class object in C++?

  • c++ function default argument object
  • c++ function default argument value for class object
  • c++ function default value for argument of complex type

1 Answer

0 like 0 dislike
by (14.9k points)

To set default value for function parameter as static created class object, use next syntax:

int someFunc(int a, FooCls fooObj = FooCls(), double bar = 5.73);

or with transfer several parameters to overloaded class constructor:

int someFunc(int a, FooCls fooObj = FooCls(5, true, 1.8f), double bar = 5.73);

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.