I am trying to take a pointer to an instance of a function template and pass it to void *:
#include <stdio.h>
void plainFunction(int *param) {}
template <typename T>
void templateFunction(T *param) {}
int main() {
void *addr1=&plainFunction;
void *addr2=&templateFunction<int>;
}
I get the following error (in Visual Studio 2008)
main.cu(10) : error C2440: 'initializing' : cannot convert from 'void (__cdecl *)(T *)' to 'void *'
Context does not allow for disambiguation of overloaded function
Why is this happening? The function templateFunction(for a specific type T=int) is not overloaded. You can subtract which instance of the function I'm referring to.
If I replaced the string erroneus with:
void (*foo)(int*)=&templateFunction<int>;
void *addr2=foo;
It compiles without a problem.
Thank!
Update:
When a regular pointer void*is replaced with a dummy function pointer void(*)(), as suggested by James (thanks), this makes the error go away:
void (*addr1)()=(void(*)())&plainFunction;
void (*addr2)()=(void(*)())(&templateFunction<int>);
, , - , . , , , , . , , , .