2
我是新來的Vala,到目前爲止我認爲它很酷,但我無法理解繼承。我讀here,我應該使用base()
來調用父項構造函數。好吧,酷,似乎可以理解,但它不適合我。我一直在標題上遇到錯誤。這裏是我的代碼片段顯示:不支持鏈接到'Gtk.Box.new'
public class MyBox : Gtk.Box {
public MyBox(Gtk.Orientation orientation, int spacing) {
// I have to this
this.set_orientation(orientation);
this.set_spacing(spacing);
// I want to do this:
base(orientation, spacing);
//workaround is this:
Object(orientation: orientation, spacing: spacing);
}
}
請幫助我瞭解爲什麼對象(....)的作品,但沒有基地(...)
它不應該是一回事嗎?
這是一個完美的解釋。所以,每當我遇到一個鏈式錯誤,這將只是**方式來解決它? – RandomGuy
是的。在這些構造函數的情況下,這些參數與通過名稱將它們傳遞給Object構造函數相同,因此它不缺少任何功能。 – apmasell