Re: Error: 'this' is only defined in non-static member functions

2017-11-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/22/17 7:35 PM, Jonathan M Davis wrote: On Thursday, November 23, 2017 00:17:46 A Guy With a Question via Digitalmars-d-learn wrote: here as non-static, nested class is associated with a specific instance of the class and has access to that class instance via its outer member. - Jonathan

Re: Error: 'this' is only defined in non-static member functions

2017-11-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-11-23 01:35, Jonathan M Davis wrote: It would make sense with something like the nodes of a linked list if they needed access to the container for some reason. Pretty much any case where a an instance of a nested class is going to be associated with a specific instance of its parent

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 23, 2017 00:49:33 Mike Parker via Digitalmars-d-learn wrote: > On Wednesday, 22 November 2017 at 22:45:53 UTC, A Guy With a > > Question wrote: > > Out of curiosity, what does static mean in that context? When I > > think of a static class I think of them in the context of

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 22:45:53 UTC, A Guy With a Question wrote: Out of curiosity, what does static mean in that context? When I think of a static class I think of them in the context of Java or C# where they can't be instantiated and where they are more like namespaces that you

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 23, 2017 00:17:46 A Guy With a Question via Digitalmars-d-learn wrote: > > here as non-static, nested class is associated with a specific > > instance of the class and has access to that class instance via > > its outer member. > > > > - Jonathan M Davis > > Hmmm...now you

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread A Guy With a Question via Digitalmars-d-learn
here as non-static, nested class is associated with a specific instance of the class and has access to that class instance via its outer member. - Jonathan M Davis Hmmm...now you have me very intrigued. What is a use-case where you'd want to use a non-static embedded class? Sorry if I'm

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 22, 2017 22:45:53 A Guy With a Question via Digitalmars-d-learn wrote: > On Wednesday, 22 November 2017 at 22:37:46 UTC, Steven > > Schveighoffer wrote: > > On 11/22/17 5:36 PM, Steven Schveighoffer wrote: > >> This allows access to the outer class's members. So you need >

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread A Guy With a Question via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 22:45:53 UTC, A Guy With a Question wrote: On Wednesday, 22 November 2017 at 22:37:46 UTC, Steven Schveighoffer wrote: On 11/22/17 5:36 PM, Steven Schveighoffer wrote: This allows access to the outer class's members. So you need an instance to instantiate. I

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread A Guy With a Question via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 22:37:46 UTC, Steven Schveighoffer wrote: On 11/22/17 5:36 PM, Steven Schveighoffer wrote: This allows access to the outer class's members. So you need an instance to instantiate. I bet it's the same for interfaces. All that being said, the error message is

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/22/17 5:36 PM, Steven Schveighoffer wrote: This allows access to the outer class's members. So you need an instance to instantiate. I bet it's the same for interfaces. All that being said, the error message is quite lousy. -Steve

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/22/17 5:19 PM, A Guy With a Question wrote: I have an interface where I have a classes embedded in it's scope (trying to create something for the classes that implement the interface can use for unittesting).     interface IExample     {     // stuff ...     class Tester    

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

2017-11-22 Thread A Guy With a Question via Digitalmars-d-learn
I have an interface where I have a classes embedded in it's scope (trying to create something for the classes that implement the interface can use for unittesting). interface IExample { // stuff ... class Tester { } } I'm trying to make an instance

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

2015-07-29 Thread remi thebault via Digitalmars-d-learn
Hello I have this weird error trying to achieve something simple: module list_test; // import wayland.util; template Id(alias a) { alias Id = a; } template ParentOf(alias member) { alias ParentOf = Id!(__traits(parent, member)); } template wl_container_of(alias member) {

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

2015-07-29 Thread anonymous via Digitalmars-d-learn
; } void main() { wl_container_of!(item.link).get(); /* Error: 'this' is only defined in non-static member functions, not main */ } I'm not sure what's going on here, if this should or shouldn't work. The error message isn't exactly good. Slapping `static` on `get` seems to make

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

2015-07-29 Thread remi thebault via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 22:12:38 UTC, anonymous wrote: Slapping `static` on `get` seems to make it work: static size_t get() {return member.offsetof;} Good slap, thanks! you solved my problem I guess the compiler thinks that since `item.link` is an instance member, it

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

2012-01-17 Thread Matej Nanut
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

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

2012-01-17 Thread Alex Rønne Petersen
On 17-01-2012 12:23, Matej Nanut wrote: 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

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

2012-01-17 Thread H. S. Teoh
On Tue, Jan 17, 2012 at 12:23:55PM +0100, Matej Nanut wrote: 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

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

2012-01-17 Thread Matej Nanut
On 17 January 2012 16:54, H. S. Teoh hst...@quickfur.ath.cx wrote: This may be the cause of your trouble. If the nested class references members in the outer class, then moving it outside will break it, since it won't have an outer scope anymore. T -- Only boring people get bored. -- JM

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

2012-01-17 Thread Timon Gehr
On 01/17/2012 06:02 PM, Matej Nanut wrote: On 17 January 2012 16:54, H. S. Teohhst...@quickfur.ath.cx wrote: This may be the cause of your trouble. If the nested class references members in the outer class, then moving it outside will break it, since it won't have an outer scope anymore. T

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

2012-01-17 Thread Matej Nanut
On 17 January 2012 18:29, Timon Gehr timon.g...@gmx.ch wrote: I'm quite sure that the error in your code occurs for the same reason as in the following code snippet: class C{    class D{}    static make(){return new D();} // error } You can fix it by making D static: class C{    static

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

2012-01-17 Thread H. S. Teoh
On Tue, Jan 17, 2012 at 06:58:55PM +0100, Matej Nanut wrote: [...] Your explanation was nice, but now I'd like to know what the difference of a non-static vs. a static class is, if they're defined top-level? Or are they then the same? I don't expect anyone to thoroughly explain things to me,

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

2012-01-17 Thread Matej Nanut
On 17 January 2012 19:07, H. S. Teoh hst...@quickfur.ath.cx wrote: Andrei's book (The D Programming Language) is quite thorough in explaining these D constructs. It's a highly recommended buy if you're doing serious work in D. T -- The two rules of success: 1. Don't tell everything you

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

2012-01-17 Thread Timon Gehr
On 01/17/2012 07:13 PM, Matej Nanut wrote: On 17 January 2012 19:07, H. S. Teohhst...@quickfur.ath.cx wrote: Andrei's book (The D Programming Language) is quite thorough in explaining these D constructs. It's a highly recommended buy if you're doing serious work in D. T -- The two rules of

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

2012-01-17 Thread Jonathan M Davis
On Tuesday, January 17, 2012 19:13:02 Matej Nanut wrote: I've been thinking on getting that for a while now. How up to date is it? Or does it explain such general concepts that I shouldn't be worried about that at all? Everyone seems to be recommending it so I don't see why I shouldn't get it.

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

2012-01-17 Thread H. S. Teoh
On Tue, Jan 17, 2012 at 07:13:02PM +0100, Matej Nanut wrote: On 17 January 2012 19:07, H. S. Teoh hst...@quickfur.ath.cx wrote: Andrei's book (The D Programming Language) is quite thorough in explaining these D constructs. It's a highly recommended buy if you're doing serious work in D.

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

2012-01-17 Thread Timon Gehr
On 01/17/2012 06:58 PM, Matej Nanut wrote: On 17 January 2012 18:29, Timon Gehrtimon.g...@gmx.ch wrote: I'm quite sure that the error in your code occurs for the same reason as in the following code snippet: class C{ class D{} static make(){return new D();} // error } You can fix it

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

2012-01-17 Thread H. S. Teoh
On Tue, Jan 17, 2012 at 08:25:28PM +0100, Timon Gehr wrote: [...] In other words, non-static nested classes can reference non-static fields of the enclosing class. [...] [...] void main() { auto a = new A; auto b = a.new B; // construct an 'A.B' with 'a' in implicit 'outer' field

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

2012-01-17 Thread Stewart Gordon
For future reference and to elaborate on what others have said, if you're asking for help solving a problem with your code, then please: 1. Post a small, self-contained testcase that demonstrates the problem straight out of the box. Tips here: http://www.sscce.org/ 2. Post full compiler

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

2012-01-16 Thread Matej Nanut
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 {

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

2012-01-16 Thread Timon Gehr
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