Error: 'this' is only defined in non-static member functions
Steven Schveighoffer
schveiguy at yahoo.com
Wed Nov 22 22:36:41 UTC 2017
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
> {
>
> }
> }
>
> I'm trying to make an instance of it like:
>
> auto tester = new IExample.Tester();
>
> And I get the above error.
Hm... not sure how this works for inner classes of Interfaces, but if
it's anything like inner classes of classes, then they have a hidden
'outer' pointer pointing at the owning instance of the class.
This allows access to the outer class's members. So you need an instance
to instantiate.
I bet it's the same for interfaces.
What you probably want is a static class, which will remove that connection:
static class Tester
...
-Steve
More information about the Digitalmars-d-learn
mailing list