Results 1 to 3 of 3

Thread: Inheritance Question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382

    Inheritance Question

    When I'm inheriting a class, how do I inherit the base classes New() method as well? Example:

    Code:
    Public Class CList
      Inherits ArrayList
    
    End Class
    When I create a new instance of an ArrayList, I get the option to add the capacity to the array list as so..

    Code:
    Dim al As New ArrayList(10)
    But when I create an instance of my class that inherits the arraylist, I don't get the option to intialize the capacity

    Code:
    Dim cl As New CList(???)
    I figured it would automatically inherit the New() method , Is there a keyword to use the base class initialization code when initializing a child class?

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Inheritance Question

    Hi

    You always to add the constructors
    Code:
    public sub new ()
    end sub
    public sug new(byval size as integer) 
    end sub
    And if your class uses unmanaged resourses its a good idea to implement the IDisposable interface.

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Inheritance Question

    Sorry but constructors are not inheritable.

    You can do Asgorath suggestions and to take it a step further you can call the base class's constructor to do the work.

    Code:
    Public Sub New(ByVal size As Integer)
         MyBase.New(size)
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width