473,804 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.I tems.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 1626
On 2004-01-21, Jim Heavey <Ji*******@nosp am.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.I tems.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*******@nosp am.com> wrote in message
news:Xn******** *************** **********@207. 46.248.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.I tems.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
1716
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 &elem(*iter);
1
2447
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 classes ("UploadedTemplate", "UploadedPresentation") which inherit from "UploadedItem")... so far so good. I have overriden the CreateElement method of "ProccessLog" and it creates the correct elements as expected. The problem is I need to override...
2
2235
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 xml files arriving from a PC inventory scanner we use. I wish to deserialize them and then process them.
6
6288
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 Exception instead." ..NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library (2004) http://www.aw-bc.com/catalog/academic/product/0,1144,0321154894-DS,00.html Exception Management...
4
6598
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
2964
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 vector<Corres>{ public: void addCorres(Corres& c); //it do little more than push_back function. }
7
2501
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
1565
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 the identical structure and properties. the only difference between them is there methods and that one is a collection class and the other is not. currently the code starts like this:
4
1701
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 : public virtual base
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10087
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.