473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Inheriting Existing Classes

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
2 1608
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: JustSomeGuy | last post by:
this doesn't want to compile.... class image : public std::list<element> { element getElement(key k) const { image::iterator iter; for (iter=begin(); iter != end(); ++iter) { element...
1
by: john diss | last post by:
hello there everyone.. I have created a class called "ProcessLog" inheriting from XmlDocument and two classes ("UploadedItem", "ProcessError") inheriting from XmlElement. I then have two...
2
by: Peter Bates | last post by:
Hi, I'm just getting used to XSDObjectGen and i have the following question. Can i use a class inherited from a class generated by XSDObjectGen with XmlSerialize? Specifically, I have many...
6
by: Russell Mangel | last post by:
Jeffery Richter makes the following statement in two books, the first was written in 2004, the latter in 2002. "You should not define new exception classes derived from ApplicationException; use...
4
by: Michael C# | last post by:
Does anyone know of any sample code for inheriting from the FileDialog or CommonDialog classes? I need to create a customized OpenFileDialog with some additional combo boxes on it. Thanks
24
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public...
7
by: Amu | last post by:
Hi i am stuck up in a part of project where i have to inherit the VC++ template classes into C#.net. Please provide me the solution for this .
5
by: jc | last post by:
RE: Two Classes with the same Data Structure.. saving code? Inheriting a structure? I have two classes. One in Inherits System.Collections.CollectionBase, the other does not, but they both have...
4
by: AalaarDB | last post by:
struct base { int x, y, z; base() {x = 0; y = 0; z = 0;}; base(int x1, int y1, int z1) {x = x1; y = y1; z = z1;}; }; struct intermediate1 : public virtual base {}; struct intermediate2 :...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.