So you have a function that takes an in-out parameter, which it is going to change in order to pass information to the caller.
But you want the parameter to be optional.
So your solution is to force the parameter to appear as the in parameter, requiring the callers to move the arguments (which would usually mean that they lost any state that they had or might be in an unspecified state). This is a bad, bad design. You will confuse callers with a weird API created for the convenience of internal implementation of the function. You should design an API for users, not developers.
You can either do what the Deduplicator offers and divide it into two functions: one that provides a dummy object that will be provided as an in-out parameter and then discarded:
void Foo(Bar& b) { } void Foo() { Bar dummy{}; Foo(dummy); }
or since what you think is necessary is a link that may be null, stop using the link and use the correct language function to pass anything by reference, which may be null:
void Foo(Bar* b) { }
source share