How do I make the following code work properly?
The non-template version compiles perfectly but the template version fails miserably. Why template version fails to figure out which function version to call and how to fix it? I thought about adding to template class AT operator that implicitly converts to BT but it doesn't work either.
class A {};
class B
{
public:
B(A){};
};
void func(B){};
template<typename T>
class AT {};
template<typename T>
class BT
{
public:
BT(AT<T>){};
};
template<typename T>
void funcT(BT<T>){};
int main()
{
func(A{});
funcT(AT<int>{}); // unable to deduce the funcT template argument
funcT<int>(AT<int>{}); // compiles but I don't want to write that
return 0;
}
There are dumb fixes like writing function version that accepts AT<T>
and casts it to BT<T>
. But I don't want to write a bunch of functions when everything should work as is. I could understand it if it was an ambiguous call...
Aucun commentaire:
Enregistrer un commentaire