我写了一个代码,它是关于 GLib.Tree 的。但不知道如何使用搜索方法。
Valadoc 有一个例子,并且有效!
下面是我的代码:
[indent = 4]
def cmp (a: string, b: string): int
return strcmp (a, b)
init
var t = new Tree of string, string (cmp)
t.insert ("a", "aaa")
t.insert ("b", "bbb")
var needle = "A"
fun: TreeSearchFunc = def (k)
return strcmp (k.down(), needle.down())
var ret = t.search (fun)
错误!
错误:名称
down' does not exist in the context of
K'
再试一次:
fun: TreeSearchFunc of string = def (k)
错误!
错误:“GTreeSearchFunc”未声明
TreeSearchFunc 说明:
public delegate int TreeSearchFunc (K key)
如果我想写一个 TreeSearchFunc 委托?怎么做?