Your examples don't work because template argument deduction fails for foo()
. With C++11 you're allowed to specify default template arguments for function templates, so you change the definition to
template<typename T = void*> void foo(T par = nullptr) {return;}
With C++03 I don't know of any way other than to explicitly specify the template argument.
The reason the template argument is not deduced from the default argument is because the standard states that is a non-deduced context.
From N3691, §14.8.2.5/5
The non-deduced contexts are:
...
— A template parameter used in the parameter type of a function parameter that has a default argument that is being used in the call for which argument deduction is being done.