Click to See Complete Forum and Search --> : Difference in template resolving (MSVC, gcc)


LeaetherStrip
November 2nd, 2002, 08:46 AM
Hi again!

This is the simple sample of code:



//...

template<class T, T t_inst>
void dosmth(T& ret){
ret = t_inst;
}

void dosmth(int& ret){
ret = 5;
}

int main(int argc, char* argv[])
{
int toret;
dosmth(toret);

return 0;
}


By design, void dosmth(int&) should be used. It's really so - in gcc. But Visual C++ refuses to compile this code, saying: error C2783: 'void __cdecl dosmth(T &)' : could not deduce template argument for 't_inst'.

Why VC doesn't use non-template function? And how this behaviour can be overriden?

Regards!

zdf
November 4th, 2002, 06:21 AM
As far as I know there is no way to change vc++’s behavior. It simply does not implement the whole standard. Your code works on Borland’s 5.5 and Comeau's 4.3 (http://www.comeaucomputing.com/tryitout).

Regards,