据我所知制作sealed
去掉在VTable中查找还是我错?如果我创建了一个类sealed
,这是否意味着类层次结构中的所有虚拟方法也都被标记为sealed
?如何摆脱虚拟表?密封类
例如:
public class A {
protected virtual void M() { ........ }
protected virtual void O() { ........ }
}
public sealed class B : A {
// I guess I can make this private for sealed class
private override void M() { ........ }
// Is this method automatically sealed? In the meaning that it doesn't have to look in VTable and can be called directly?
// Also what about O() can it be called directly too, without VTable?
}
不,方法调用仍然是虚拟的。 – InBetween
你几乎是对的 - 你需要将该方法标记为“密封”,而不是班级。 – Nat
@Nat,但正如我下面评论 - 本文说,类可以标记密封http://codebetter.com/patricksmacchia/2008/01/05/rambling-on-the-sealed-keyword/我更容易标记类而不是每个虚拟方法。 –