當我想將base
轉發到合適的接口類型(即A
),以便我可以調用doA()時,出現解析錯誤。我知道base
(http://cs.hubfs.net/topic/None/58670)有點特別,但到目前爲止我還沒有找到解決這個問題的方法。F#上傳基地
有什麼建議嗎?
type A =
abstract member doA : unit -> string
type ConcreteA() =
interface A with
member this.doA() = "a"
type ExtA() =
inherit ConcreteA()
interface A with
override this.doA() = "ex" // + (base :> A).doA() -> parse error (unexpected symbol ':>' in expression)
((new ExtA()) :> A).doA() // output: ex
工作C#當量:
public interface A
{
string doA();
}
public class ConcreteA : A {
public virtual string doA() { return "a"; }
}
public class ExtA : ConcreteA {
public override string doA() { return "ex" + base.doA(); }
}
new ExtA().doA(); // output: exa
在F#中我認爲'override ...'應該放在'ExtA'下,而不是接口。 – 2013-02-22 21:36:56