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

发布于 2024-09-13 02:05:37 字数 875 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城缀染半城烟沙 2024-09-20 02:05:37

尝试使用

Attached.remove(place.name());

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

Try using

Attached.remove(place.name());

Notice the use of parentheses instead of square brackets. Square brackets are used for indexing only.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文