Vladimir Grigoriev
2009-12-21 14:15:16 UTC
Let consider the code
struct A
{
};
struct B: public A
{
}
template <typename T>
void f( const T &, const T & )
{
}
int _tmain(int argc, _TCHAR* argv[])
{
f( A(), B() );
}
The Microsoft C++ compiler generated the error
error C2782: 'void f(const T &,const T &)' : template parameter 'T' is
ambiguous
see declaration of 'f'
could be 'B'
or 'A'
However when I substitute the template function to usual function
void f( const A &, const A & )
{
}
The code is compiled.
Should the compiler take into account that there is only one available
conversion from B object ti A object when it instantiates the template
function? Why does it report the error though B type can not be used as T?
Vladimir Grigoriev
struct A
{
};
struct B: public A
{
}
template <typename T>
void f( const T &, const T & )
{
}
int _tmain(int argc, _TCHAR* argv[])
{
f( A(), B() );
}
The Microsoft C++ compiler generated the error
error C2782: 'void f(const T &,const T &)' : template parameter 'T' is
ambiguous
see declaration of 'f'
could be 'B'
or 'A'
However when I substitute the template function to usual function
void f( const A &, const A & )
{
}
The code is compiled.
Should the compiler take into account that there is only one available
conversion from B object ti A object when it instantiates the template
function? Why does it report the error though B type can not be used as T?
Vladimir Grigoriev