473,546 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

constructor on inherited object

I am having a problem getting my inherited object to compile. I am trying
to add another variable to the constuctor and I cannot get past different
variations of the following message:

No overload for method 'dataObjAnc' takes '0' arguments... I tweak the code
and the 0 changes to 1 etc...

I've seen the thread in here about coding the constructor as
inheritedObjCon str( ... ) : this() but I cannot figure out how to pass the
required parameter for the base object down to the base for processing.

I understand that the compiler is telling me that it is trying to fall back
onto a default constructor but that it doesn't exist. What is the
recommended approach here. I doesn't seem like I should have to duplicate
the single parameter constructor in the child object...

This is what I have

class dataObjAnc
{
dataObjAnc(stri ng name)
{
do somthing...
}

}

class detailDataObjAn c : dataObjAnc
{
dataObjAnc(stri ng name, Int32 progID)
{
set progID
pass name to base constructor
}

thx

Nov 16 '05 #1
3 2282
This compiles but is this the correct way to be doing this?

public dataObjProgram( string objName) : base(objName){}
public dataObjProgram( string objName, Int32 progID) : this(objName)
{
programID = progID;
}

"Jack Addington" <ja********@sha w.ca> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I am having a problem getting my inherited object to compile. I am trying
to add another variable to the constuctor and I cannot get past different
variations of the following message:

No overload for method 'dataObjAnc' takes '0' arguments... I tweak the
code and the 0 changes to 1 etc...

I've seen the thread in here about coding the constructor as
inheritedObjCon str( ... ) : this() but I cannot figure out how to pass
the required parameter for the base object down to the base for
processing.

I understand that the compiler is telling me that it is trying to fall
back onto a default constructor but that it doesn't exist. What is the
recommended approach here. I doesn't seem like I should have to duplicate
the single parameter constructor in the child object...

This is what I have

class dataObjAnc
{
dataObjAnc(stri ng name)
{
do somthing...
}

}

class detailDataObjAn c : dataObjAnc
{
dataObjAnc(stri ng name, Int32 progID)
{
set progID
pass name to base constructor
}

thx

Nov 16 '05 #2
Jack Addington <ja********@sha w.ca> wrote:
I am having a problem getting my inherited object to compile. I am trying
to add another variable to the constuctor and I cannot get past different
variations of the following message:


<snip>

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

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

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Jack Addington <ja********@sha w.ca> wrote:
I am having a problem getting my inherited object to compile. I am
trying
to add another variable to the constuctor and I cannot get past different
variations of the following message:


<snip>

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

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4

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

Similar topics

7
28974
by: Dominique | last post by:
Suppose I have: class A { A(int x, int y); }; and class B: public A {
3
4538
by: Jun | last post by:
I have following script <script> var Animal = function(name){ this.name = name; } Animal.prototype.eat = function (food) {
8
2967
by: trying_to_learn | last post by:
Why do we need to explicitly call the copy constructor and the operator = , for base class and member objects in composition? ....book says "You must explicitly call the GameBoard copy-constructor or the default constructor is automatically called instead" Why cant the compiler do this on its own. if we are making an object through copr...
45
6313
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using parameters, I get CS1501 (no method with X arguments). Here's a simplified example which mimics the circumstances: namespace InheritError { //...
8
3660
by: Mike - EMAIL IGNORED | last post by:
I have a class that may or may not be inherited. Its constructor calls a function that should be called only if the class is not inherited. Is there a way to tell, other than simply passing a bool argument? Thanks for your suggestions. Mike.
2
3214
by: slolife | last post by:
See any problem with this code: Here's my Base page class: Public Class BasePage Inherits System.Web.UI.Page Protected m_NeedAlerts As Boolean Private Sub Page_Init(ByVal sender As Object, ByVal e As
6
359
by: =?Utf-8?B?T2xkQnV0U3RpbGxMZWFybmluZw==?= | last post by:
I forget the right syntax.... If I Have multiple signatures for a constructor, but I want each to call a "main" version of the constructor...I can't remember how to do this in C#.... public MyClass(string a, string b) { Do something.... }
1
1367
by: appu | last post by:
Hi all, Suppose class A is inherited from class B and Class B is inherited from class C. Could anyone explain on how the C++ compiler construct the A object and how is A object destroyed by compiler when it is out of scope. Can anyone explain what does the compiler do in these process? thanks in advance -karups
2
1430
by: tshad | last post by:
Using VB.Net VS 2003 I am getting the following message when I call my 2nd constructor. Too many arguments to 'Public Sub New()'. I have 2 constructors: ********************************** Public Sub New() End Sub
0
7435
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...
0
7694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
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...
0
7792
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...
1
5360
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...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
747
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...

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.