Error: 'this' is only defined in non-static member functions, not parse

Matej Nanut matejnanut at
Mon Jan 16 15:49:26 PST 2012

Hey everyone,

I, once again, have a problem with an error I can't seem to figure out!

The situation:
- a class, inherited by five other classes;
- the class having a static function which returns one
  if its subclasses depending on the input of a string.

Something like this:

class Node
  static Node parse(ref string s)
    /* Get value to switch by, an enum. */
    auto switchable = /* ... */;
    final switch (switchable)
      case return new OneNode(s);
      case Blah.two: return new TwoNode(s);
    /* ... */

And I get the mentioned error. I don't understand it:
is it saying I'm using `this' in a static member function
called `parse'? Am I insane; where am I referencing it?

The other classes are in this form:

class OneNode : Node
  /* ... stuff ... */
  this(ref string s)
    /* Does stuff with `s'. */

Do you need more information?

Thank you,

More information about the Digitalmars-d-learn mailing list