【发布时间】:2009-04-29 13:13:12
【问题描述】:
编译器错误 关键字“this”在当前上下文中不可用
delegate void CallBack(int i);
class A
{
public A(CallBack cb) { }
}
class B : A
{
public B() : base(new CallBack(this.f)){}
private void f(int i) { }
}
为什么会出现这个错误? 作为一种解决方案,我想在 A() 中提供一个无参数受保护的 ctor 并拥有
class B : A
{
public B() : base() // inherit the new A() ctor
{
base.cb = new CallBack(this.f); //this is allowed here
}
//...
}
【问题讨论】:
标签: c# inheritance constructor