473,396 Members | 2,020 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,396 software developers and data experts.

Overriding constructors

I'm writing a class that derives from ServiceBase and it says in the
documentation for the constructor of ServiceBase that if you override
the base class constructor, you should explicitly call it in the
constructor of your derived class.

As far as I know a constructor cannot be overridden only overloaded,
is this a mistake or have I been mislead.
Nov 16 '05 #1
2 6819
You should be able to write a constructor for your class and explicitly call
the base implementation, effectively overriding it. You can also overload
the constructor, if you need params passed in when you create the object. I
have not tried with ServiceBase, in particular, but your new derived class
can have a default constructor as well as any number of parameterized
constructors.

I do not necessarily consider this to be overriding so much, so the
terminology is suspect.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"Samer" <sa*******@hotmail.com> wrote in message
news:a2**************************@posting.google.c om...
I'm writing a class that derives from ServiceBase and it says in the
documentation for the constructor of ServiceBase that if you override
the base class constructor, you should explicitly call it in the
constructor of your derived class.

As far as I know a constructor cannot be overridden only overloaded,
is this a mistake or have I been mislead.

Nov 16 '05 #2
Samer <sa*******@hotmail.com> wrote:
I'm writing a class that derives from ServiceBase and it says in the
documentation for the constructor of ServiceBase that if you override
the base class constructor, you should explicitly call it in the
constructor of your derived class.

As far as I know a constructor cannot be overridden only overloaded,
is this a mistake or have I been mislead.


You're correct - constructors can't be overridden, as they're not
inherited. However, I believe it's basically saying that unless you
*want* to call the parameterless constructor of the base type (in which
case, making that fact explicit isn't a bad idea if your constructor
takes any arguments) you have to call a different constructor of the
base type.

See http://www.pobox.com/~skeet/csharp/constructors.html for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ali Eghtebas | last post by:
Hi, I have 3 questions regarding the code below: 1) Why can't I trap the KEYDOWN while I can trap KEYUP? 2) Is it correct that I use Return True within the IF-Statement? (I've already read...
42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
4
by: TS | last post by:
i have a class that i'm trying to understand that overrides BaseApplicationException's methods as follows. What i dont' understand is that i have never seen the inherit ":" on a method signature,...
17
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that...
3
by: pagates | last post by:
Hello Gurus, I have a listview, and I only want to add unique items. The problem is, my code is blowing by my "Contains" statement, adding the item, and then hitting my Compare code in the...
2
by: project | last post by:
Hi every body, Any body can help me the following doubts? 1. what is constructor? 2. what is destructor? 3. what is overriding function. 4. different between structure and array 5. what is...
1
by: Carl Fenley | last post by:
I've been programming exclusively in C# for the last few years but am now working on a project where I am required to write all code in VB.NET. I'm trying to create a class with multiple...
3
by: John | last post by:
Before anything else, thanks Marina, Workgroups and Ralf, for your help so far. I am now able to better define the question! After adding more console printout lines to CSum, I tried all...
10
by: CAFxX | last post by:
I'm trying to solve a problem with my code but can't come up with a solution. Suppose I have a "class" A with its constructor (that I can't modify directly) function A() { /* constructor code...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.