www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Base class' constructor is not implicitly inherited for immutable

reply Piotr Mitana <piotrekm niepodam.pl> writes:
Hello, I have this code:

immutable class Base
{
	this() {}
}

immutable class Derived : Base {}

void main()
{
	new immutable Derived();
}

I'd like class Derived to automatically inherit the default 
constructor from Base. However, this is not the case:

main.d(6): Error: class main.Derived cannot implicitly generate a 
default ctor when base class main.Base is missing a default ctor

Is it a bug or it should be like this?
Jul 19 2017
next sibling parent bauss <jj_1337 live.dk> writes:
On Wednesday, 19 July 2017 at 16:00:56 UTC, Piotr Mitana wrote:
 Hello, I have this code:

 immutable class Base
 {
 	this() {}
 }

 immutable class Derived : Base {}

 void main()
 {
 	new immutable Derived();
 }

 I'd like class Derived to automatically inherit the default 
 constructor from Base. However, this is not the case:

 main.d(6): Error: class main.Derived cannot implicitly generate 
 a default ctor when base class main.Base is missing a default 
 ctor

 Is it a bug or it should be like this?
I'd say it's a bug. There was a similar issue at one point where it wouldn't consider default constructor with default args.
Jul 20 2017
prev sibling next sibling parent Eugene Wissner <belka caraus.de> writes:
On Wednesday, 19 July 2017 at 16:00:56 UTC, Piotr Mitana wrote:
 Hello, I have this code:

 immutable class Base
 {
 	this() {}
 }

 immutable class Derived : Base {}

 void main()
 {
 	new immutable Derived();
 }

 I'd like class Derived to automatically inherit the default 
 constructor from Base. However, this is not the case:

 main.d(6): Error: class main.Derived cannot implicitly generate 
 a default ctor when base class main.Base is missing a default 
 ctor

 Is it a bug or it should be like this?
Interesting that the same code without immutable works.
Jul 20 2017
prev sibling parent arturg <var.spool.mail700 gmail.com> writes:
On Wednesday, 19 July 2017 at 16:00:56 UTC, Piotr Mitana wrote:
 Hello, I have this code:

 immutable class Base
 {
 	this() {}
 }

 immutable class Derived : Base {}

 void main()
 {
 	new immutable Derived();
 }

 I'd like class Derived to automatically inherit the default 
 constructor from Base. However, this is not the case:

 main.d(6): Error: class main.Derived cannot implicitly generate 
 a default ctor when base class main.Base is missing a default 
 ctor

 Is it a bug or it should be like this?
compiles with: dmd 2.073 fails with: dmd 2.074 dmd 2.075
Jul 20 2017