nested class inherits containing class accessing private instance members 
Author Message
 nested class inherits containing class accessing private instance members

Hi All,
   In the context of nested classes VB.NET compiler
behaves different from what the VB language reference on
MSDN says.

If I compile and run this code it runs fine.

Option Strict On
Imports Microsoft.VisualBasic

Public MustInherit class Parent
        Private i As Integer
        Sub New
                i = 23
        End Sub
        Shared Function Create As Parent
                Return New Child1
        End Function
        MustOverride Sub Foo
        Private Class Child1
                Inherits Parent
                Overrides Sub Foo
                        MsgBox(Me.i)
                End Sub
        End Class
Shared Sub Main
        Dim x As Parent
        x = Parent.Create
        x.Foo
End Sub

But this snippet below from the URL
( http://www.*-*-*.com/
us/vblr7/html/vastmClass.asp?frame=true) says the exact
opposite.
"Binding of unqualified names in nested classes will
search the members of the class itself, then the members
of its containing class, and so on out to the outermost
containing class. Private members of outer classes can be
referenced but an error will be given for references to
instance members of containing classes.
Nested classes cannot inherit from their containing class.
"
Who is wrong the MSDN reference or the compiler?
Please guide me so that I can decide on whether to contnue
using this feature or not?

TIA
Sankar

End Class
I wonder if the reference is wrong, or the compiler is
buggy.



Wed, 14 Dec 2005 10:05:28 GMT  
 nested class inherits containing class accessing private instance members
Quote:
>-----Original Message-----
>Hi All,
>   In the context of nested classes VB.NET compiler
>behaves different from what the VB language reference on
>MSDN says.

>If I compile and run this code it runs fine.

>Option Strict On
>Imports Microsoft.VisualBasic

>Public MustInherit class Parent
>    Private i As Integer
>    Sub New
>            i = 23
>    End Sub
>    Shared Function Create As Parent
>            Return New Child1
>    End Function
>    MustOverride Sub Foo
>    Private Class Child1
>            Inherits Parent
>            Overrides Sub Foo
>                    MsgBox(Me.i)
>            End Sub
>    End Class
>Shared Sub Main
>    Dim x As Parent
>    x = Parent.Create
>    x.Foo
>End Sub

>But this snippet below from the URL
>(http://www.msdn.microsoft.com/library/en-
>us/vblr7/html/vastmClass.asp?frame=true) says the exact
>opposite.
>"Binding of unqualified names in nested classes will
>search the members of the class itself, then the members
>of its containing class, and so on out to the outermost
>containing class. Private members of outer classes can be
>referenced but an error will be given for references to
>instance members of containing classes.
>Nested classes cannot inherit from their containing class.
>"
>Who is wrong the MSDN reference or the compiler?
>Please guide me so that I can decide on whether to
contnue
>using this feature or not?

>TIA
>Sankar

>End Class
>I wonder if the reference is wrong, or the compiler is
>buggy.
>.



Wed, 14 Dec 2005 10:25:26 GMT  
 nested class inherits containing class accessing private instance members



Quote:
> Hi All,
>    In the context of nested classes VB.NET compiler
> behaves different from what the VB language reference on
> MSDN says.

> If I compile and run this code it runs fine.

> Option Strict On
> Imports Microsoft.VisualBasic

> Public MustInherit class Parent
> Private i As Integer
> Sub New
> i = 23
> End Sub
> Shared Function Create As Parent
> Return New Child1
> End Function
> MustOverride Sub Foo
> Private Class Child1
> Inherits Parent
> Overrides Sub Foo
> MsgBox(Me.i)
> End Sub
> End Class
> Shared Sub Main
> Dim x As Parent
> x = Parent.Create
> x.Foo
> End Sub

> But this snippet below from the URL
> (http://www.msdn.microsoft.com/library/en-
> us/vblr7/html/vastmClass.asp?frame=true) says the exact
> opposite.
> "Binding of unqualified names in nested classes will
> search the members of the class itself, then the members
> of its containing class, and so on out to the outermost
> containing class. Private members of outer classes can be
> referenced but an error will be given for references to
> instance members of containing classes.
> Nested classes cannot inherit from their containing class.
> "
> Who is wrong the MSDN reference or the compiler?
> Please guide me so that I can decide on whether to contnue
> using this feature or not?

> TIA
> Sankar

> End Class
> I wonder if the reference is wrong, or the compiler is
> buggy.

What exactly is the problem? Which sentence? I tested the code and it
behaves as expected.

--
Armin



Wed, 14 Dec 2005 14:28:18 GMT  
 nested class inherits containing class accessing private instance members
The code works right? But the MSDN reference says
"Nested classes cannot inherit from their containing
class."
But in my code at the line "Private Class Child1 Inherits
Parent", Child1 is a nested class and it is inheriting
from the containing class.

Quote:
>-----Original Message-----


Newsbeitrag

>> Hi All,
>>    In the context of nested classes VB.NET compiler
>> behaves different from what the VB language reference
on
>> MSDN says.

>> If I compile and run this code it runs fine.

>> Option Strict On
>> Imports Microsoft.VisualBasic

>> Public MustInherit class Parent
>> Private i As Integer
>> Sub New
>> i = 23
>> End Sub
>> Shared Function Create As Parent
>> Return New Child1
>> End Function
>> MustOverride Sub Foo
>> Private Class Child1
>> Inherits Parent
>> Overrides Sub Foo
>> MsgBox(Me.i)
>> End Sub
>> End Class
>> Shared Sub Main
>> Dim x As Parent
>> x = Parent.Create
>> x.Foo
>> End Sub

>> But this snippet below from the URL
>> (http://www.msdn.microsoft.com/library/en-
>> us/vblr7/html/vastmClass.asp?frame=true) says the exact
>> opposite.
>> "Binding of unqualified names in nested classes will
>> search the members of the class itself, then the
members
>> of its containing class, and so on out to the outermost
>> containing class. Private members of outer classes can
be
>> referenced but an error will be given for references to
>> instance members of containing classes.
>> Nested classes cannot inherit from their containing
class.
>> "
>> Who is wrong the MSDN reference or the compiler?
>> Please guide me so that I can decide on whether to
contnue
>> using this feature or not?

>> TIA
>> Sankar

>> End Class
>> I wonder if the reference is wrong, or the compiler is
>> buggy.

>What exactly is the problem? Which sentence? I tested
the code and it
>behaves as expected.

>--
>Armin

>.



Thu, 15 Dec 2005 03:13:18 GMT  
 nested class inherits containing class accessing private instance members

Quote:
> The code works right? But the MSDN reference says
> "Nested classes cannot inherit from their containing
> class."
> But in my code at the line "Private Class Child1 Inherits
> Parent", Child1 is a nested class and it is inheriting
> from the containing class.

My German docs says that nested classes can not inherit from _contained_
classes.

Nevertheless, both directions are possible: The outer class can inherit from
the inner class and vice versa. So, the sentence in the docs is superfluous.

--
Armin



Thu, 15 Dec 2005 04:27:03 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. newbie: private class variables are visible in class instances

2. Access to private members from class method

3. How-To Access Class Members Within The Same Class

4. VBA class: private members not hidden

5. Find out if somebody make an instance of a Class without having access to the Class

6. Public or Private instance of class ?

7. Problem with a vb.Net class inheriting from a c# class

8. Public Method in a class calling a private method in same class yields ByRef error

9. StatusBarPanel Collection containing panels based on different classes derived from StatusBarPanel class

10. Any problems with VBScript class containing another class?

11. Can Classes contain Arrays of Classes ???

12. instance a class from its class name

 

 
Powered by phpBB® Forum Software