Novice question about inherited constructors

Question

I am moving from Delphi to C# and hve encountered the problem:

I have the following classes and form Load event handler:

public class class1
{
public string S;
public class1( string aS )
{
S = aS;
}
}

public class class2 : class1
{
}

private void Form1_Load(object sender, System.EventArgs e)
{
class2 C2 = new class2( "string" );
label1.Text = C2.S;
}

When I try to compile I get the following errors:

No overload for method ''class1'' takes ''0'' arguments
No overload for method ''class2'' takes ''1'' arguments

What does it mean ?
Why inherited constructors are not used (as in Delphi) ?

Oleg Subachev

Solution
That is just part of the design of .NET that constructors are not inherited.
If you have a non-default constructor in a base class, you must also define
that same constructor and then pass the value up to its base.

public class2(string aS) : base(aS){...}
"Oleg Subachev" <ol**@urvb.ru> wrote in message
news:e

**************@TK2MSFTNGP02.phx.gbl...
I am moving from Delphi to C# and hve encountered the problem:

I have the following classes and form Load event handler:

public class class1
{
public string S;
public class1( string aS )
{
S = aS;
}
}

public class class2 : class1
{
}

private void Form1_Load(object sender, System.EventArgs e)
{
class2 C2 = new class2( "string" );
label1.Text = C2.S;
}

When I try to compile I get the following errors:

No overload for method ''class1'' takes ''0'' arguments
No overload for method ''class2'' takes ''1'' arguments

What does it mean ?
Why inherited constructors are not used (as in Delphi) ?

Oleg Subachev


Oleg Subachev wrote:
I am moving from Delphi to C# and hve encountered the problem:
<snip>
When I try to compile I get the following errors:

No overload for method ''class1'' takes ''0'' arguments
This is because the compiler is creating a default constructor for
class2, which tries to call a parameterless constructor in class1 - but
there isn''t one.
No overload for method ''class2'' takes ''1'' arguments
This is because there isn''t a constructor in class2 taking a string,
because constructors aren''t inherited.
Why inherited constructors are not used (as in Delphi) ?


If constructors were inherited, then *all* classes would have to have a
parameterless constructor, as System.Object does. I don''t know how
Delphi gets around it, but personally I''m glad constructors aren''t
inherited - it''s good to be able to mandate that any instance of a
certain class *must* go through one of the constructors I''ve specified,
even if extra constructors have been added to the base class.

I view instance creation as somewhat different to instance use - things
which can be treated the same way after they''ve been created often have
very different creation requirements.

(Having said that, I *would* like some way of specifying what
constructors *must* be present in any type implementing a specific
interface, and possibly likewise for static methods. Extra syntax would
be necessary in order to call those constructors/static methods,
however - it does all get a bit complicated.)

Jon