If the argument is optional, it must be a pointer, not a reference.
template<class T> void f(T** const = 0);
If you want the call style to be passed by reference, you need a redirector, not a default argument.
template<class T> void f_impl(T** const); template<class T> void f( T*& arg ) { return f_impl(&arg); } template<class T> void f( void ) { return f_impl<T>(0); }
If you want to avoid null checks and simply refuse to assign to a parameter when the parameter is not set, do the following:
template<class T> void f(T*&); template<class T> void f( void ) { T* unused = 0; return f(unused); }
Note that T in the version with no arguments, is not an inferred context, but was also the original when the parameter was not provided.
source share