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

Timon Gehr timon.gehr at gmx.ch
Mon Jan 16 17:33:59 PST 2012


On 01/17/2012 12:49 AM, Matej Nanut wrote:
> 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 Blah.one: 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?
>
Yes; It is extremely hard to solve the problem when there is no code 
snippet given which exhibits the problematic behavior in question.



More information about the Digitalmars-d-learn mailing list