Reputation: 899
I have a variadic template member function defined as:
template<typename ... Params>
VAlgorithm* CreateAlgorithm(const char *objectName, const char *className, Params ... par)
and I would like to take the address of the specialized version where Params contains no type (which I call the "empty" specialization), ie., of:
VAlgorithm* CreateAlgorithm(const char *objectName, const char *className)
I tried in several ways. The naive way:
&AlgorithmFactory::CreateAlgorithm<>
(since, for example, &AlgorithmFactory::CreateAlgorithm< int > works) and a more explicit way:
(VAlgorithm* (*)(const char*, const char*))AlgorithmFactory::CreateAlgorithm<>
With the explicit way, GCC 4.7.1 says:
error: insufficient contextual information to determine type
It seems that the "empty" specialization is not understood by the compiler, which interprets the missing template types as a lack of info and not as "no types" information. What is the correct way to do this? (Sorry for the potentially naive question but I'm fairly new to variadic templates and I found no documentation on this topic). Thanks
Upvotes: 4
Views: 408
Reputation: 157414
Your code should work; see e.g. http://liveworkspace.org/code/6253cf45f416be60879b93aa74c24de8
All the following syntaxes work for me:
struct S {
template<typename... Args> static int *foo(const char *, const char *, Args...);
};
int main() {
(int *(*)(const char *, const char *))S::foo<>;
(int *(*)(const char *, const char *))S::foo;
(int *(&)(const char *, const char *))S::foo<>;
(int *(&)(const char *, const char *))S::foo;
int *(&f)(const char *, const char *) = S::foo<>;
int *(&g)(const char *, const char *) = S::foo;
int *(*h)(const char *, const char *) = S::foo<>;
int *(*i)(const char *, const char *) = S::foo;
}
Upvotes: 1