Error: 'this' is only defined in non-static member functions, not parse
Matej Nanut
matejnanut at gmail.com
Tue Jan 17 03:23:55 PST 2012
I will try to remove all snippets in my code that aren't relevant but still
exhibit the issue, when I find the time. What I forgot to mention is that
this error appeared when I did some so-called "refactoring"; I moved a
nested class out of its parent, since I wanted it visible on the outside.
I moved it back now and reference it by Parent.Child.<stuff>, which is
just as good, and the error isn't there anymore, but I still don't understand
it. I must have missed some variable renaming or something. Or I was
just plain sloppy. As mentioned I will post a complete snippet with the
error sometime until friday.
On 17 January 2012 02:33, Timon Gehr <timon.gehr at gmx.ch> wrote:
> 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