4

私は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の単なるバグですか?

4

1 に答える 1

4

使ってみてください

Attached.remove(place.name());

角括弧の代わりに括弧が使用されていることに注意してください。角かっこはインデックス作成にのみ使用されます。

于 2010-08-04T20:32:34.643 に答える