B
bz
Hi,
I have a base class with several constructors and I want to create a
derived class, as below
class MyBase {
public MyBase() {...}
public MyBase(int ID) {...}
public MyBase(string ID_str) {...}
//....
public void Load() {....}
}
class MyDerived: MyBase {
public MyDerived() {....}
}
If I create a variable of type MyDerived, I can access Load method,
which obvious executes the Load from MyBase
However, I cannot create a variable of type MyDerived using other than
default constructor
MyDerived ob1 = new MyDerived(); // compiles ok
MyDerived ob2 = new MyDerived(SomeID);
This later gives me compilation error that there is no constructor
with 1 parameter.
So, the contructors from base class are not inherited, as with other
public methods? Do I have to define in MyDerived all constructors I
want to use, and they'll call the corresponding constructors from
MyBase?
Thanks
I have a base class with several constructors and I want to create a
derived class, as below
class MyBase {
public MyBase() {...}
public MyBase(int ID) {...}
public MyBase(string ID_str) {...}
//....
public void Load() {....}
}
class MyDerived: MyBase {
public MyDerived() {....}
}
If I create a variable of type MyDerived, I can access Load method,
which obvious executes the Load from MyBase
However, I cannot create a variable of type MyDerived using other than
default constructor
MyDerived ob1 = new MyDerived(); // compiles ok
MyDerived ob2 = new MyDerived(SomeID);
This later gives me compilation error that there is no constructor
with 1 parameter.
So, the contructors from base class are not inherited, as with other
public methods? Do I have to define in MyDerived all constructors I
want to use, and they'll call the corresponding constructors from
MyBase?
Thanks