Domanda

Ho il seguente codice nel 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
}

Ogni volta che provo a compilare con dmd2.0 Ottengo i seguenti errori

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

Gli attuali consigli di documentazione D2.0 per uso array.remove [tasto] per quello che sto cercando di fare, ma sembra che il compilatore pensa che io sto cercando di richiamare una funzione std.c (STDC?). Perché questo essere che si verificano? Questo è solo un bug in dmd2.0?

È stato utile?

Soluzione

Prova a usare

Attached.remove(place.name());

Si noti l'uso delle parentesi, invece di parentesi quadre. Le parentesi quadre sono utilizzate per l'indicizzazione solo.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top