C++ how to make a function that has optional parameters

Viewed 214

I want to make a function that has parameters like here void example(int x, int y, int z); but I dont have to put z in there like this example(34, 21); is that possible in C++?

2 Answers

You basically have two options

  1. Create a overloaded function that takes 2 parameters. So you would have
void example(int x, int y, int z)

and

void example(int x, int y)
  1. Assign default value to z
void example(int x, int y, int z = 0)
Related