views:

64

answers:

1

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?

+4  A: 

Try using

Attached.remove(place.name());

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

Peter Alexander
Oh gods, of course.
itsmyown
That is a really bad error message... :(
BCS
Yes, it is. The reason for the error is because D allows you to call functions of the type `fun(a)` using `a.fun` so it begins by deducing that you are trying to call `core.c.stdio.remove` and then tries to work from there.
Peter Alexander
@Peter: Thanks for the background, hopefully that will elucidate future errors for me.
itsmyown