ctor not inhrited in a classes
Zaher Dirkey
zaherdirkey at yahoo.com
Sun Jun 16 14:11:15 UTC 2019
I discussed this on IRC before years but i didnt get good answer.
Let assume I have library that used by my coworkers
In the example bellow my coworkers used SubBaseClass to create
their classes, in first version of my code I dont have ctor with
arg, and everything is fine,
but later i added parent to it and i want SubBaseClass and (child
classes) not created without parent value, i want to force them
to do that.
what happen the new ctor not inhrited to child classes, and
coworkers still can create it using (new) without parameters, we
have alot of child classes,
I want compiler stop compiling if parent not defined.
import std.stdio;
class SuperClass {
this(){
}
}
class SubBaseClass: SuperClass {
this(){
}
SubBaseClass parent;
this(SubBaseClass Parent) {
//some code to use parent etc
writeln("childclass ctor");
}
}
//CoWorkers or who are using my lib
class ChildBaseClass1: SubBaseClass {
}
class ChildBaseClass2: SubBaseClass {
}
void main()
{
//compiled
ChildBaseClass1 a = new ChildBaseClass1();
ChildBaseClass2 b = new ChildBaseClass2();
//error:is not callable using argument types
//but i need to force to use to init varables
ChildBaseClass1 a = new ChildBaseClass1(null);
ChildBaseClass2 b = new ChildBaseClass2(a);
}
More information about the Digitalmars-d
mailing list