El parámetro de plantilla no puede deducirse
No entiendo por qué T no se puede deducir en este escenario:
template<class T>
class MyType
{
T * data;
};
class MyOtherType
{
};
template<typename T>
struct MyType_OutArg
{
typedef MyType<T> & type;
};
template<typename T>
void
DoSomething(typename MyType_OutArg<T>::type obj)
{
}
void func(MyType_OutArg<MyOtherType>::type obj)
{
DoSomething(obj);
}
Desde GCC 4.7.1 con -std = c ++ 14
<source>: In function 'void func(MyType_OutArg<MyOtherType>::type)':
26 : <source>:26:20: error: no matching function for call to 'DoSomething(MyType<MyOtherType>&)'
DoSomething(obj);
^
26 : <source>:26:20: note: candidate is:
19 : <source>:19:1: note: template<class T> void DoSomething(typename MyType_OutArg<T>::type)
DoSomething(typename MyType_OutArg<T>::type obj)
^
19 : <source>:19:1: note: template argument deduction/substitution failed:
26 : <source>:26:20: note: couldn't deduce template parameter 'T'
DoSomething(obj);
^
Compiler returned: 1
Por supuesto, los siguientes trabajos:
DoSomething<MyOtherType>(obj);
Pero no estoy seguro de por qué es necesario. ¿No debería el compilador tener suficiente información?