关联数组.remove[]调用dmd 2.0中的core.stdc.stdio.remove
我在D中有以下代码关联数组.remove[]调用dmd 2.0中的core.stdc.stdio.remove,d,associative-array,dmd,D,Associative Array,Dmd,我在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
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中的一个bug吗?尝试使用
Attached.remove(place.name());
请注意使用括号而不是方括号。方括号仅用于索引。是的,它是。出现错误的原因是D允许您使用
a.fun
调用类型为fun(a)
的函数,因此它首先推断您试图调用core.c.stdio.remove
,然后尝试从那里开始工作。感谢您的背景知识,希望这能为我解释未来的错误。