473,387 Members | 1,597 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,387 software developers and data experts.

Deriving from a class with 3 constructors.

Hi,

I have a class with 3 constructors, one takes no arguments, other take
an string and other an xml document.

I want to derive another class of it, I don't need a different
constructor so I didn't override nor rewrite any of its constructors.
When I try to compile I get the error :

No overloaded method for "MyDerivedClassConstructor" takes 1 argument.

The error is on a line to create the derived class passing 1 argument.

Why this ? It seems like the derived class "dont see" the parent's
constructors ?

Nov 17 '05 #1
3 1329
What about the modifier of your constructors? Here is a sample and it
compiles without any error...
class SampleClass
{
public SampleClass() { }
public SampleClass(string s) { }
public SampleClass(XmlDocument doc) { }
}
class AnotherSampleClass : SampleClass
{
}

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET

<cr************@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi,

I have a class with 3 constructors, one takes no arguments, other take
an string and other an xml document.

I want to derive another class of it, I don't need a different
constructor so I didn't override nor rewrite any of its constructors.
When I try to compile I get the error :

No overloaded method for "MyDerivedClassConstructor" takes 1 argument.

The error is on a line to create the derived class passing 1 argument.

Why this ? It seems like the derived class "dont see" the parent's
constructors ?

Nov 17 '05 #2
> No overloaded method for "MyDerivedClassConstructor" takes 1 argument.
The error is on a line to create the derived class passing 1 argument. Why this ? It seems like the derived class "dont see" the parent's constructors ?


The derived class certainly can "see" the parent's constructors. What
it doesn't do is _inherit_ its parent's constructors. A class has
however many constructors it declares, regardless of how many
constructors its parent class has. If you want your derived class to
have all three constructors, then you must code it like this:

public class DerivedClass : ParentClass
{
public DerivedClass() : base() { }
public DerivedClass(string s) : base(s) { }
public DerivedClass(XmlDocument xml) : base(xml) { }
}

You can leave the constructor implementations blank (thus the empty
braces { } ), but you must declare the constructors and indicate which
base class constructor they should call.

Nov 17 '05 #3
Thanks, that worked !

I found other articles about this not inheritence of constructors.
I think I heard of it before, but didn't remember well.
It seemed very natural to think that I'd be able to access the parent's
constructor just like that, since they were public.

Nov 17 '05 #4

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

Similar topics

50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
8
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
6
by: Fred | last post by:
Hi I have a class defined in a library that I'd like to add some extra functionality to. This will involve adding a few member variables and a few related methods. As I understand it I can...
3
by: J.J. Feminella | last post by:
(Please disregard the previous message; I accidentally sent it before it was completed.) I have source code similar to the following. public class Vehicle { protected string dataV; // ......
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
8
by: Vincent Finn | last post by:
I know the answer to the question above is yes but my reason for asking is that it doesn't seem to work properly I have a manged C++ WinForms project In it I have a form A, I want to derive a...
15
by: Nindi73 | last post by:
HI If I define the class DoubleMap such that struct DoubleMap : public std::map<std::string, double>{}; Is there any overhead in calling std::map member functions ? Moreover are STL...
6
by: Dan Smithers | last post by:
I want to write my own class derived from the ostream class. I have been getting errors with my templates: First, I get an error writing a nested template. If I leave the function definition...
3
by: Al Grant | last post by:
Consider two translation units, (1): namespace { struct S { }; } struct D: S { virtual int f(void); }; and (2): #include <typeinfo> struct D; char const *f(D *p) { return...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...

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.