P
Pavils Jurjans
Hello,
I am having this code:
**************************************************
using System;
public class Parent
{
int a;
public Parent(int arg)
{
a = arg;
}
}
public class Child : Parent
{
public void Meth(string x)
{
Console.WriteLine("Hello from Child.Meth, id={0}", x);
}
}
**************************************************
If I try to compile this, I get error "No overload for method 'Parent' takes
'0' arguments". If I add the following code to the Child class,
public Child(int arg): base(arg)
{
}
All compiles fine. That is, compiler demands that I define constructore for
the Child class. But, what if I want to default to the Parent's constructor?
Why can't I just skip the definition of Childs constructor, and compiler
would assume that Chils constructor is the same as Parent's? Now I am forced
to add thos dummy lines to all Child classes that don't need their own
constructors, they add/overload just methods.
-- Pavils
I am having this code:
**************************************************
using System;
public class Parent
{
int a;
public Parent(int arg)
{
a = arg;
}
}
public class Child : Parent
{
public void Meth(string x)
{
Console.WriteLine("Hello from Child.Meth, id={0}", x);
}
}
**************************************************
If I try to compile this, I get error "No overload for method 'Parent' takes
'0' arguments". If I add the following code to the Child class,
public Child(int arg): base(arg)
{
}
All compiles fine. That is, compiler demands that I define constructore for
the Child class. But, what if I want to default to the Parent's constructor?
Why can't I just skip the definition of Childs constructor, and compiler
would assume that Chils constructor is the same as Parent's? Now I am forced
to add thos dummy lines to all Child classes that don't need their own
constructors, they add/overload just methods.
-- Pavils