Directly casting from pointer to template function?

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; //OK
    void *addr2=&templateFunction<int>; //Compile error
}

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>);

, , - , . , , , , . , , , .

+5
2

: ++ void*.

(, void (*)(int*) ) , (, void* ).

Visual ++, (, void* addr1 = &plainFunction;), ( /Za, , ).

, ( "" ): "templateFunction" ").

+12

. void * 4.10/2, (& section. 1.8/1). Visual Studio 2008 , .

typedef, :

typedef void(func)(int*); // declare func type
func* addr1 = &plainFunction;         // OK
func* addr2 = &templateFunction<int>; // OK
+6

All Articles