Results 1 to 4 of 4

Thread: Inherit a class with a private "New()" sub?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2004
    Location
    Kansas, USA
    Posts
    352

    Inherit a class with a private "New()" sub?

    Please forgive me if this is a dumb question but...

    I am learing how to extend a class with some properties and methods of my own design. When I create the class code and add the Inherit statement I get this error:

    Class 'PourLine' must declare a 'Sub New' because its base class 'LineClass' does not have an accessible 'Sub New' that can be called with no arguments.

    When I attempt to add a sub called "New" I get this error:

    First statement of this 'Sub New' must be a call to 'MyBase.New' or 'MyClass.New' because base class 'DesignCAD.LineClass' of 'Exploring_Capping_Classes.PourLine' does not have an accessible 'Sub New' that can be called with no arguments.

    When I try MyBase.New() the error is:

    'DesignCAD.LineClass.Private Sub New()' is not accessible in this context because it is 'Private'.

    Is there any way I can create a class that inherits the methods and properties of the base class?

    My simple code:

    Public Class PourLine
    Inherits DesignCAD.LineClass

    Sub Build()
    MyBase.New()
    End Sub
    End Class

    Thanks in advance for your help.
    Eric

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Why not make the New in the inherited class protected?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2004
    Location
    Kansas, USA
    Posts
    352
    Like This?

    Public Class PourLine
    Inherits DesignCAD.LineClass

    Protected Sub New()
    MyBase.New()


    End Sub
    End Class


    When I do I still get the same error which is:

    'DesignCAD.LineClass.Private Sub New()' is not accessible in this context because it is 'Private'.

    Thanks,
    Eric

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    No. The class you are inheriting. Assuming you have access to the code to do that. Otherwise, it wasnt designed with being inherited in mind.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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