Inherited functions not visible?

M

M O J O

Hi,

I've created a MasterForm which all my forms in my project must derive from.

In my MasterForm, I've overloaded the New event with this code:


Public Sub New(ByVal SomeText As String)
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
'Do something with SomeText...
End Sub


I've add an inherited form MyForm which inherits from my MasterForm.

Here's my question....

Why can't I write Dim MyNewForm As New MyForm("Just a test") ?

The overloaded New(ByVal SomeText As String) is not visible when I'm
creating a new MyForm (which inherits from MasterForm).

What am I doing wrong?

Thanks.

M O J O
 
A

Armin Zingler

M O J O said:
Hi,

I've created a MasterForm which all my forms in my project must
derive from.

In my MasterForm, I've overloaded the New event with this code:


Public Sub New(ByVal SomeText As String)
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent()
call 'Do something with SomeText...
End Sub


I've add an inherited form MyForm which inherits from my
MasterForm.

Here's my question....

Why can't I write Dim MyNewForm As New MyForm("Just a test") ?

The overloaded New(ByVal SomeText As String) is not visible when I'm
creating a new MyForm (which inherits from MasterForm).

What am I doing wrong?

Constructors are not inherited. They can not be inherited because the
constructor is tied to the specific instance of a class. In other words, the
constructors determine how you can create an instance of the class they
belong to.
 
J

Jay B. Harlow [MVP - Outlook]

M O J O
In addition to Armin's comments.

Constructors are never inherited! As you may have the case where the derived
class requires a different set of constructors then the base class, hence it
is left up to the designer of the derived class to implement the correct set
of constructors for the derived class.

Basically its (IMHO) "cleaner" to need to add the constructors you need to
the derived class, rather then have some syntax to remove constructors that
may have been inherited and you don't need, especially when a new
constructor could be added to the base, and you missed "removing" that
constructor from the derived class...

You sample reminds me that the base form needs to call the base form's
InitializeComponent, and the derived form needs to call the derived form's
InitializeComponent! Which further highlights why constructors are never
inherited.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top