无法将函数转换为委托

时间:2012-09-01 23:24:18

标签: function delegates d

我有这个功能

 private ulong Html(ubyte[] data)
  {
    return data.length;
  }

我希望使用toDelegate()函数转换为委托。我试过了:

client.onReceive = toDelegate(&Html);

但我收到一条错误消息:

lixo.d(722): Error: not a property client.onReceive
/home/$/D/libs/arsd/dom.d(743): Warning: statement is not reachable
/usr/include/d/dmd/phobos/std/range.d(595): Error: static assert  "Cannot put a dchar[] into a Appender!(char[])"
/usr/include/d/dmd/phobos/std/format.d(1758):        instantiated from here: put!(Appender!(char[]),dchar[])
/usr/include/d/dmd/phobos/std/format.d(1514):        instantiated from here: formatRange!(Appender!(char[]),dchar[],char)
/usr/include/d/dmd/phobos/std/conv.d(101):        instantiated from here: formatValue!(Appender!(char[]),dchar[],char)
/usr/include/d/dmd/phobos/std/conv.d(757):        ... (1 instantiations, -v to show) ...
/usr/include/d/dmd/phobos/std/conv.d(244):        instantiated from here: toImpl!(char[],dchar[])
/home/$/libs/arsd/dom.d(2115):        instantiated from here: to!(dchar[])

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我想/home/$/D/libs/arsd/dom.d库有一个名为' Html '的结构或类。尝试将“ Html ”功能重命名为其他功能,看看是否有帮助。

如果它仍然不起作用,您可能需要向我们展示更多代码,因为您的示例似乎对我有用: http://dpaste.dzfl.pl/fd729f3d

(之前我见过类似的错误。由于某些原因,自dmd 2.060以来,“非属性”错误发生很多,即使真正的错误没有关系。)