ネタ元 → NyaRuRuさんのコメント@思想の違い
public abstract class Base {
public System.Action<int> Foo;
public Base() {
Foo = foo;
}
protected abstract void foo(int i);
}
public class Derived : Base {
protected override void foo(int i) {
System.Console.WriteLine("Derived.foo({0})",i);
}
}
public class Program {
public static void Main() {
Base x = new Derived();
x.Foo(3);
}
}
ほほー、ありもしないabstract(抽象)メソッドをdelegateしちゃってますね。
同じよなこと、C++でもできっかな?
#include <iostream>
class Base {
public:
typedef void (Base::*action)(int);
action Foo;
Base() {
Foo = &Base::foo;
}
protected:
virtual void foo(int i) =0;
};
class Derived : public Base {
protected:
virtual void foo(int i) {
std::cout << "Derived.foo(" << i << ")\n";
}
};
int main() {
Base* x = new Derived();
(x->*(x->Foo))(3);
}
…ははは、できた♪