By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,064 Members | 1,524 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,064 IT Pros & Developers. It's quick & easy.

Inheriting Existing Classes

P: n/a
I amd playing around with inheritance a little in VB.Net

If I create a new class which inherits from ListViewItem and I am only
wanting to override the ToString Method. In this situation, If I only
override the "ToString" method, I find that I only have a single
constructor. Do I have to clone all of the constructor methods and then
execute the MyBase.New(....) methods for each of those constructors? If I
am inheriting all methods and data, why would I have to re-create these
methods.

When I create an instance of this new class, it seems to create the new
class just fine, but when I go to add that object into my combobox I get a
"Object reference not set to an instance of an object." My code looks like
the following...

Dim item As New SpListViewItem(items(indx))
cboFormatType.Items.Add(item)

My "item" is populated as I expected, so I do not understand the error.

Any idea?

Thanks in advance for your assistance!!!!!!!!
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 2004-01-21, Jim Heavey <Ji*******@nospam.com> wrote:
I amd playing around with inheritance a little in VB.Net

If I create a new class which inherits from ListViewItem and I am only
wanting to override the ToString Method. In this situation, If I only
override the "ToString" method, I find that I only have a single
constructor. Do I have to clone all of the constructor methods and then
execute the MyBase.New(....) methods for each of those constructors? If I
am inheriting all methods and data, why would I have to re-create these
methods.

Constructors are not inherited. You don't need to call MyBase.New()
unless you want to call one of the parameterized constructors - since
the compiler will automatically call the base class default constructor
for you. But, if you need to pass arguments to your base class then you
need to do it with MyBase.New...
When I create an instance of this new class, it seems to create the new
class just fine, but when I go to add that object into my combobox I get a
"Object reference not set to an instance of an object." My code looks like
the following...

Dim item As New SpListViewItem(items(indx))
cboFormatType.Items.Add(item)

My "item" is populated as I expected, so I do not understand the error.

Any idea?


Hard to say with out seeing the code for the ToString method... Which
is likely the source of the error, since that is what the combobox will
call by default...

--
Tom Shelton [MVP]
Nov 20 '05 #2

P: n/a
Jim,
In addition to Tom'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...

Hope this helps
Jay

"Jim Heavey" <Ji*******@nospam.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
I amd playing around with inheritance a little in VB.Net

If I create a new class which inherits from ListViewItem and I am only
wanting to override the ToString Method. In this situation, If I only
override the "ToString" method, I find that I only have a single
constructor. Do I have to clone all of the constructor methods and then
execute the MyBase.New(....) methods for each of those constructors? If I
am inheriting all methods and data, why would I have to re-create these
methods.

When I create an instance of this new class, it seems to create the new
class just fine, but when I go to add that object into my combobox I get a
"Object reference not set to an instance of an object." My code looks like the following...

Dim item As New SpListViewItem(items(indx))
cboFormatType.Items.Add(item)

My "item" is populated as I expected, so I do not understand the error.

Any idea?

Thanks in advance for your assistance!!!!!!!!

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.