문제

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?

도움이 되었습니까?

해결책

Try using

Attached.remove(place.name());

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top