gpt4 book ai didi

d - 关联数组 .remove[] 在 dmd 2.0 中调用 core.stdc.stdio.remove

转载 作者:行者123 更新时间:2023-12-01 01:33:26 24 4
gpt4 key购买 nike

我在 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 中的一个错误吗?

最佳答案

尝试使用

Attached.remove(place.name());

请注意使用括号而不是方括号。方括号仅用于索引。

关于d - 关联数组 .remove[] 在 dmd 2.0 中调用 core.stdc.stdio.remove,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3408729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com