How access outer class this from inner class? 
Author Message
 How access outer class this from inner class?

I have this problem in C++, C#, java. :-)

class A
{
    class B
    {
       b() { want to access this pointer of A here }
    }

Quote:
}

Thanks


Sun, 21 Mar 2004 05:30:46 GMT  
 How access outer class this from inner class?
I may be wrong, but I don't think that is possible in C#.

--
Jonathan Allen


Quote:
> I have this problem in C++, C#, java. :-)

> class A
> {
>     class B
>     {
>        b() { want to access this pointer of A here }
>     }
> }

> Thanks



Sun, 21 Mar 2004 07:10:51 GMT  
 How access outer class this from inner class?
Calvin,
Jonathan is basically correct. C# & .Net does not directly support this.

This may be obvious: ;-)

What I would suggest is saving a reference to the outer class inside your
inner class, pass it on the constructor (assuming only the outer class can
create an inner class...

Hope this helps
Jay


Quote:
> I have this problem in C++, C#, java. :-)

> class A
> {
>     class B
>     {
>        b() { want to access this pointer of A here }
>     }
> }

> Thanks



Sun, 21 Mar 2004 10:06:34 GMT  
 How access outer class this from inner class?
Have the B constructor take a reference to an A class.  Then either
have the "parent" object pass back objects of the inner class pre-
loaded with references to itself or manually connect the two when you
instantiate a B.



Quote:
> I have this problem in C++, C#, java. :-)

> class A
> {
>     class B
>     {
>        b() { want to access this pointer of A here }
>     }
> }

> Thanks

Tim


Sun, 21 Mar 2004 10:24:15 GMT  
 How access outer class this from inner class?


Quote:
> Calvin,
> Jonathan is basically correct. C# & .Net does not directly support this.

> This may be obvious: ;-)

To a Java programmer, it is far from obvious.

Quote:
> What I would suggest is saving a reference to the outer class inside your
> inner class, pass it on the constructor (assuming only the outer class can
> create an inner class...

Which is what the Java compiler does implicitly. The  this  pointer of
the outer class can be referred to as  OuterClass.this  IIRC.

The .NET team decided you have to do it explicitly.

ON/***Remove the slow slimy animal from my reply address***



Sun, 21 Mar 2004 14:29:16 GMT  
 How access outer class this from inner class?
Ole,
Hmm...

You got the obvious associated with the wrong statement! ;-)

What may be obvious is what Java does implicitly. Save a reference to the
outer class in the inner class...

Sorry it wasn't obvious, which of my two statements I was implying was
obvious ;-)

Jay


Quote:


> > Calvin,
> > Jonathan is basically correct. C# & .Net does not directly support this.

> > This may be obvious: ;-)

> To a Java programmer, it is far from obvious.

> > What I would suggest is saving a reference to the outer class inside
your
> > inner class, pass it on the constructor (assuming only the outer class
can
> > create an inner class...

> Which is what the Java compiler does implicitly. The  this  pointer of
> the outer class can be referred to as  OuterClass.this  IIRC.

> The .NET team decided you have to do it explicitly.

> ON/***Remove the slow slimy animal from my reply address***



Mon, 22 Mar 2004 11:11:51 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Special access in Inner Classes

2. inner classes and access problem

3. Difference between outer and inner declaration of function??

4. Inner class ?

5. Inner Classes

6. Templates/Inner Classes

7. Inner class problems

8. assign different inner classes

9. Template inner-class compile/link problem

10. Inner classes as friends

11. Class in class OR class derived from class?

12. MessageMap in inner class

 

 
Powered by phpBB® Forum Software