Michel Fortin <[email protected]> wrote:
I stubbled upon this yesterday:
Template This Parameters
TemplateThisParameters are used in member function templates to pick up
the type of the this reference.
import std.stdio;
struct S
{
const void foo(this T)(int i)
{
writeln(typeid(T));
}
}
<http://www.digitalmars.com/d/2.0/template.html>
Looks like you could return the type of this this way...
The problem of template this parameters is that it doesn't work as one
might expect:
class A {
void bar( this T )( ) {
writeln( typeid( T ) );
}
}
class B : A {
}
void main( ) {
A a = new B;
a.bar();
}
Surely this will print modulename.B, right?
Wrong. It prints modulename.A, as A is the type of the reference
from which the function is called. It looks like a way to automagically
override a function for each subclass, but no.
--
Simen