"constructor missing initializer for const field" when field is set inside an init function

Robert M. Münch robert.muench at saphirion.com
Sat Jan 4 14:50:54 UTC 2020

This following code gives an error: "constructor a.this missing 
initializer for const field myThing"

class a {
	const myThing*;

		myThing = initMyThing();

I have to explicitly set the const field inside this(). As long as I 
only have one constructor that's OK. I prefer to have an init() 
function to collect all things to setup an object.

Shouldn't the compiler find out that myThing is set during construction 
in this case?

Robert M. Münch
smarter | better | faster

More information about the Digitalmars-d mailing list