The following code fails to compile with:
Error: template main.C.myTemplate2 cannot deduce function from argument types !()(int), candidates are:
main.C.myTemplate2(this P, T)(T val)
And the code:
void main(string[] args)
{
D.myTemplate3(0);
}
class C
{
static void myTemplate2(this P, T)(T val)
{
P.myTemplate(val);
}
}
class D : C
{
static void myTemplate3(T)(T val)
{
myTemplate2(val);
}
static void myTemplate(T)(T val)
{
}
}
Removing `this P` from the template parameter list of `myTemplate2` allows it to compile, but doesn't give access to `myTemplate`.
This makes it very difficult to abstract out templated code into a base class that is dependent upon the implementation in the derived class.
Comment #1 by nick — 2018-03-09T19:06:07Z
The spec says:
"TemplateThisParameters are used in member function templates to pick up the type of the this reference."
Using them in static methods is an enhancement, so this is a duplicate.
*** This issue has been marked as a duplicate of issue 10488 ***