views:

798

answers:

2

For some reason trying to pass a pointer to this function to a varadic function produces the following error:

1>c:\... : error C2664: 'PyArg_ParseTuple' : cannot convert parameter 3 from 'int (__cdecl *)(PyObject *,void *)' to '...'
1>        Context does not allow for disambiguation of overloaded function

PyArg_ParseTuple(args, "O&O&:CreateWindow",
    &Arg_Size2U<1>, &size,
    &Arg_String<2>, &title);

I'm not sure what the problem is, since the template function has no over loads, and the template paremeters are defined explicitly, so theres no question over which function to pass a pointer for...

Is there some way around this that does not invlove create lots of versions for each argument conversion function, but can still have the argument number in the exception if there an error? (Better yet some way to pass the argument number as a paremeter, so there are not multiple copies of the function in my dll.)

EDIT: This also seems to result in compile errors. Is there no way to create a function pointer to a template function, or do I need to do it diffrently from normal functions?

int (*sizeConv)(PyObject *,void *) = Arg_MakeSize2U<1>;
1>c:\... : error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(PyObject *,void *)' to 'int (__cdecl *)(PyObject *,void *)'
1>        None of the functions with this name in scope match the target type

The function is declared as:

template<int ARG> int Arg_MakeSize2U(PyObject *obj, void *out)

EDIT2: adding the address of operator gave yet another diffrent error...

int (*sizeConv)(PyObject *,void *) = &Arg_MakeSize2U<1>;

1>c:\... : error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'int (__cdecl *)(PyObject *,void *)'
1>        None of the functions with this name in scope match the target type
A: 

From the second error it sounds like the compiler can't find the implementation. Is your template function definition in the header file where you declare your template?

Budric
Yes, however that header is included by the precompiled header, could that cause a problem under VS2008?
Fire Lancer
I included the header directly in the cpp where I was having the troble, exaclty the same errors.
Fire Lancer
What I meant was the body of the template must be in the header. If it isn't that could explain the second error.template <class T>void myFunc(T arg) { arg+1;}
Budric
When I said yes, I meant yes that the entire implementation of the template function was in the header.
Fire Lancer
+1  A: 

This compiles fine in VC++ 2008:

struct PyObject;

template<int ARG> int Arg_MakeSize2U(PyObject *obj, void *out)
{
    return 0;
}

int main()
{
    int (*sizeConv)(PyObject *,void *) = &Arg_MakeSize2U<1>;
    sizeConv(0, 0);
}

So you must be doing something differently. Maybe you do have an overload and you haven't noticed. Posting more context would help diagnose the problem better.

Yuyo