I'm trying to compile some code in VS2019 with /permissive- that involves both templates and overloading and wierd things are happening. (https://godbolt.org/z/fBbQu6)
As in the godbolt, when my templateFunc() is declared between two overloads like so:
namespace Foospace {
class A;
void func(A*) {};
template<class T> void templateFunc() { Foospace::func((T*)0); }
class B;
void func(B*) {};
void func() { Foospace::templateFunc<B>(); }
}
I get error C2664: 'void Foospace::func(Foospace::A *)': cannot convert argument 1 from 'T *' to 'Foospace::A *'
If I move the templateFunc() below the overloads, it obviously works:
namespace Foospace {
class A;
void func(A*) {};
class B;
void func(B*) {};
template<class T> void templateFunc() { Foospace::func((T*)0); }
void func() { Foospace::templateFunc<B>(); }
}
And if I move templateFunc() before both overloads that also works:
namespace Foospace {
template<class T> void templateFunc() { Foospace::func((T*)0); }
class A;
void func(A*) {};
class B;
void func(B*) {};
void func() { Foospace::templateFunc<B>(); }
}
And if I keep templateFunc() between the two overloads but simply remove the Foospace
namespace qualifier from the call to func() then suddenly that also works too:
namespace Foospace {
class A;
void func(A*) {};
template<class T> void templateFunc() { func((T*)0); }
class B;
void func(B*) {};
void func() { Foospace::templateFunc<B>(); }
}
What is going on here?