I have a function that takes two parameters. The first parameter is an int& which the function will set to some "return" value. The second parameter is a pointer and is optional. The caller can pass a valid pointer if the caller wishes it to be initialized, and if not the default value is nullptr.
void find_lis(uint32_t& count,
vector<uint32_t>* output = nullptr)
{ }
All is well. However, I want to make the second parameter a reference, and allow caller the same option to provide one or not, what should I use as the default value?
void find_lis(uint32_t& count,
vector<uint32_t>& output = ???)
{ }
I tried a few things, but they cause a compiler error. However, the following at least compiles, but I am not sure if it is right?
void find_lis(uint32_t& count,
vector<uint32_t>& output = *(new vector<uint32_t>()))
{ }
In the pointer case, I can easily check if the caller passed in a second parameter by comparing value to nullptr. However, in the reference case, I don't see any such easy check.