digitalmars.D.learn - Inheriting Base Constructors?
- AJG (16/16) Aug 12 2005 Hi there,
- Ben Hinkle (6/22) Aug 13 2005 It would be impossible for a subclass to prevent a superclass's ctor fro...
- AJG (18/29) Aug 13 2005 Ah. I got the wrong impression from what I read below. I was hoping that...
- Ben Hinkle (6/40) Aug 14 2005 Try using default parameters to shorten the list of ctors - that's all I...
Hi there, I have a base abstract class which implements, among other things, two base constructors and a base destructor. My problem is in the derived classes. The destructor works fine because there can only be one. Thus, when the object is destroyed, the base destructor gets called and all is good. The constructors, however, are giving me trouble. Specifically, the derived class is not inheriting one of the constructors. In the D docs, it says: http://www.digitalmars.com//d/class.html "If there is no constructor for a class, but there is a constructor for the base class, a default constructor of the form: this() { } is implicitly generated." Why won't it do that with constructors that have parameters? Thanks, --AJG. PS: Another related problem: If the base class declares the default constructor "this()" as protected, why doesn't it have any bearing in the derived classes?
Aug 12 2005
The constructors, however, are giving me trouble. Specifically, the derived class is not inheriting one of the constructors.Derived classes don't inherit ctors. Making an instance of a class is different than calling methods of a class.In the D docs, it says: http://www.digitalmars.com//d/class.html "If there is no constructor for a class, but there is a constructor for the base class, a default constructor of the form: this() { } is implicitly generated." Why won't it do that with constructors that have parameters?It would be impossible for a subclass to prevent a superclass's ctor from being used to create a subclass - which doesn't make sense.Thanks, --AJG. PS: Another related problem: If the base class declares the default constructor "this()" as protected, why doesn't it have any bearing in the derived classes?I'm not sure what you mean by bearing. You should be able to call it from the derived class but not from other code.
Aug 13 2005
In article <ddkqgo$2vg5$1 digitaldaemon.com>, Ben Hinkle says...Ah. I got the wrong impression from what I read below. I was hoping that since: is implicitly generated, and then that turns implicitly into: That other constructors would follow. I.e. that: which would turn into: Would also be implicitly generated if the super class constained a super ctor: Does that make sense? Is there any other way to accomplish that? I mean, without having all derived classes have to implement the sub-ctor with the parameter just to call super(a)?The constructors, however, are giving me trouble. Specifically, the derived class is not inheriting one of the constructors.Derived classes don't inherit ctors. Making an instance of a class is different than calling methods of a class.I meant that if the super ctor is protected, is there a way to enforce that the sub ctor remain protected? Thanks, --AJG.PS: Another related problem: If the base class declares the default constructor "this()" as protected, why doesn't it have any bearing in the derived classes?I'm not sure what you mean by bearing. You should be able to call it from the derived class but not from other code.
Aug 13 2005
"AJG" <AJG_member pathlink.com> wrote in message news:ddmh0e$14hg$1 digitaldaemon.com...In article <ddkqgo$2vg5$1 digitaldaemon.com>, Ben Hinkle says...Try using default parameters to shorten the list of ctors - that's all I can think of to cut down on the number. How many are there, out of curiosity? Presumably the number of ctors is somewhere below 4 - usually 1 or 2.Ah. I got the wrong impression from what I read below. I was hoping that since: is implicitly generated, and then that turns implicitly into: That other constructors would follow. I.e. that: which would turn into: Would also be implicitly generated if the super class constained a super ctor: Does that make sense? Is there any other way to accomplish that? I mean, without having all derived classes have to implement the sub-ctor with the parameter just to call super(a)?The constructors, however, are giving me trouble. Specifically, the derived class is not inheriting one of the constructors.Derived classes don't inherit ctors. Making an instance of a class is different than calling methods of a class.Nothing comes to mind.I meant that if the super ctor is protected, is there a way to enforce that the sub ctor remain protected?PS: Another related problem: If the base class declares the default constructor "this()" as protected, why doesn't it have any bearing in the derived classes?I'm not sure what you mean by bearing. You should be able to call it from the derived class but not from other code.
Aug 14 2005