关联数组 .remove[] 在 dmd 2.0 中调用 core.stdc.stdio.remove
我在 D 中有以下代码
import std.stdio;
class Thing
{
// Fields
private string Name;
// Accessors
public string name() { return Name; }
}
class Place: Thing
{
// Fields
private Place[string] Attached;
// Modifiers
public void attach(Place place) { Attached[place.name()] = place; }
public void detach(Place place) { Attached.remove[place.name()]; } // error line
}
每当我尝试使用 dmd2.0 进行编译时,我都会收到以下错误
Error: function core.stdc.stdio.remove (in const(char*) filename) is not callable using argument types (Place[string])
Error: cannot implicitly convert expression (this.Attached) of type Place[string] to const(char*)
Error: remove((__error)) must be an array or pointer type, not int
当前的 D2.0 文档建议使用 array.remove[key] 来完成我想要做的事情,但它看起来像编译器认为我正在尝试调用 std.c(stdc?) 函数。为什么会出现这种情况呢?这只是dmd2.0中的一个错误吗?
I have the following code in D
import std.stdio;
class Thing
{
// Fields
private string Name;
// Accessors
public string name() { return Name; }
}
class Place: Thing
{
// Fields
private Place[string] Attached;
// Modifiers
public void attach(Place place) { Attached[place.name()] = place; }
public void detach(Place place) { Attached.remove[place.name()]; } // error line
}
Whenever I try to compile with dmd2.0 I get the following errors
Error: function core.stdc.stdio.remove (in const(char*) filename) is not callable using argument types (Place[string])
Error: cannot implicitly convert expression (this.Attached) of type Place[string] to const(char*)
Error: remove((__error)) must be an array or pointer type, not int
The current D2.0 documentation advices to use array.remove[key] for what I'm trying to do, but it looks like the compiler thinks I'm trying to call a std.c(stdc?) function. Why would this be occurring? Is this just a bug in dmd2.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
注意使用括号而不是方括号。方括号仅用于索引。
Try using
Notice the use of parentheses instead of square brackets. Square brackets are used for indexing only.