Single "alias this"
    Deokjae Lee 
    asitdepends at gmail.com
       
    Sun Jul 25 07:45:37 PDT 2010
    
    
  
Thank you for the reply.
Actually I tested a code like this.
//interfaces first, base class last
class Foo : I1, I2, Base {}
This doesn't compile.
I didn't know the order of base class and interfaces matter.
> As for alias this, it's not about dynamic polymorphism like class
> inheritance. All it does is forward unresolved method calls to the alias
> this'ed member.
I'm reading TDPL and it says "alias this" in a relation with multiple 
subtyping. Polymorphism can be achieved using a nested class extending 
the base class and implicit conversion. So, I can't get the role of the 
"alias this" differentiated from inheritance.
And...
import std.stdio;
class A {
	void func() {
		writeln("A");
	}
}
class B : A {
	override void func() {
		writeln("B");
	}
}
class C {
	private B b;
	alias b this;
	
	this() {
		b = new B();
	}
}
void main() {
	C c = new C();
	c.func();
	A a = c;
	a.func();
}
The output is the following.
B
zsh: segmentation fault  ./Test3
Hmm... Are the last two lines of main illegal?
    
    
More information about the Digitalmars-d-learn
mailing list