Archived

This topic is now archived and is closed to further replies.

template < arguments deduction > issue

This topic is 5042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Tried this with VC++ 7.1 :
template < class A1, class A2 >
int init1( A1 a1, A2 a2 )
{
	return;
}

template < class R, class A1, class A2 >
R init2( A1 a1, A2 a2 )
{
	return R();
}

int(*pfn1)(int,int) = &init1; // OK


int(*pfn2)(int,int) = &init2; // error C2440: 'initialisation' : impossible to convert 'overloaded-function' into 'void (__cdecl *)(int,int)'


int(*pfn3)(int,int) = init2;  // error C2440: 'initialisation' : impossible to convert 'T1 (__cdecl *)(T2,T3)' into 'int (__cdecl *)(int,int)'
:\ ... Why can't the compiler deduce the return type ?! Is this a VC issue or some kind of feature that lies within C++ ? Thanks for your help. [edited by - cnstrnd on February 22, 2004 11:07:16 AM]

Share this post


Link to post
Share on other sites
What do you mean exactly by signature ?
The signature of pfn1 is ''int(int,int)'' right ?

Also, I don''t understand why this other piece of code compiles :

template < class S >
struct deduce;

template < class R >
struct deduce<R(*)()>
{
typedef R return_type;
};

template < class R, class A1 >
struct deduce<R(*)(A1)>
{
typedef R return_type;
typedef A1 argument1_type;
};

template < class R, class A1, class A2 >
struct deduce<R(*)(A1,A2)>
{
typedef R return_type;
typedef A1 argument1_type;
typedef A2 argument2_type;
};

typedef int(*pfn_t)(int,int);

typedef deduce<pfn_t>::return_type return_type;

Share this post


Link to post
Share on other sites