Results 1 to 2 of 2

Thread: Inheritance help

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    LA
    Posts
    57

    Question Inheritance help

    I’m trying to inherit System.IO.StreamReader in to my class
    But I’m getting an error “ Class ‘MyClass’ must declare a ‘Sub New’ because its base its class ‘StreamReader’ does not have an accessible ‘Sub New ‘ that can be called with no arguments.



    Code:
    Imports System.IO
    
    Public Class Info
        Inherits StreamReader
        
    
    End Class
    Please help.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What are you making that you need to inherit from StreamReader?

    Anyway since StreamReader has no default constructor then you have to have constructor for your derived class that creates the base class, passing in the parameters for its constructor. In other words since you can't do:
    VB Code:
    1. Dim sr As New IO.StreamReader()
    then you have to have a constructor in your object that handles passing in whatever. Add something like this to your class:
    VB Code:
    1. Public Sub New()
    2.     MyBase.New(AddParametersToCreateTheBaseObjectHere)
    3. 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