Your third attempt should work, after fixing the errors ;)
template<typename T> void baz(T*);
template<typename T> class TemplatingHelper {
typedef void (*foo_t)(T*);
static foo_t dummy;
};
template<typename T> // template-declaration
typename TemplatingHelper<T>::foo_t // type
TemplatingHelper<T>::dummy // name
= baz; // initializer
I agree it's redundant, but it follows a general form of declaration:
type name initializer ;
even though the name has already been declared and given a type inside the class template.
In this case, it's a template-declaration, so we need to add the template<typename T>
part; this is required since we could also refer to a partial specialization:
template<typename T, typename U> class TemplatingHelper<T(*)(U)>
{
typedef T(*foo_t)(U);
static foo_t dummy;
};
template<typename T, typename U>
typename TemplatingHelper<T(*)(U)>::foo_t
TemplatingHelper<T(*)(U)>::dummy
= baz;
As the type is required and precedes the declared name, we need to explicitly state the scope where to find it:
TemplatingHelper<T>::foo_t
Unfortunately, name lookup requires to put a typename
before this qualified name. See Where and why do I have to put the “template” and “typename” keywords?