erik.ohlin
erik.ohlin

Reputation: 127

Inheriting into Base Class Namespace

I have a Class A that has some protected members that I want my base Class B to access. I also want Class B to be in the namespace under Class A. Is this possible?

Namespace BLL
   Public Class A
      Protected varA As Integer
      Protected varB As String
   End Class
End Namespace

Namespace BLL.A
   Public Class B
      Inherits A
      Public Sub setA()
         varA = 3
         varB = "test"
      End Sub
   End Class
End Namespace

I then want to be able to access Class B like so:

BLL.A.B.setA()

When I do this I am getting an error "'A' is ambiguous in the namespace BLL". What am I doing wrong?

Upvotes: 0

Views: 235

Answers (1)

the_lotus
the_lotus

Reputation: 12748

A isn't a namespace, it's a class. You'll have to put B inside of class A.

Namespace BLL
    Public Class A
        Protected varA As Integer
        Protected varB As String
    End Class
End Namespace

Namespace BLL
    Partial Public Class A
        Public Class B
            Inherits A
            Public Sub setA()
                varA = 3
                varB = "test"
            End Sub
        End Class
    End Class
End Namespace

Which I do not recommend of doing. The framework rarely have classes inside of class, especially public ones. But, I'm just one random person on the internet :)

If you really want namespace, I would rename class A something like CarBase and put the other classes in a namespace called Car.

Upvotes: 2

Related Questions