...ing logging 4.0

はてなブログに移行しました。D言語の話とかいろいろ。

仮想関数のディスパッチ

import std.stdio;

interface I
{
	void f();
	void g();
}

class A : I
{
	class B
	{
		void f()
		{
			writeln("hello");
		}
		void g()
		{
			writeln("world");
		}
	}
	
	private B b;
	
	this()
	{
		b = new B;
	}
	
	auto opDispatch(string name)()
	{
		mixin("b." ~ name ~ "();");
	}
}

void main()
{
	A a = new A;//I a = new A;にしたり...
	a.f();
	a.g();
}
main.d(9): Error: class main.A interface function I.f isn't implemented
main.d(9): Error: class main.A interface function I.g isn't implemented

う〜ん・・・.
できないのか.
opDispatchを alias b this; にしても同じ.
Aの仮想関数を全部Bに転送するのめんどいお・・・.