alias this and struct allocation

faissaloo faissaloo at gmail.com
Mon May 6 14:48:56 UTC 2019


I've been having some memory issues (referenced objects turning 
to nulls for no apparent reason) and I was wondering if I've 
misunderstood how allocation works when instantiating a struct 
that uses alias this:

	import std.stdio;
	
	struct Parent {
		int a;
	}
	struct Child {
		Parent base;
		alias base this;
		int y;
	}
	auto myStructMaker() {
		return new Child(Parent(10),20);
	}
	
	void main()
	{
		writeln(*myStructMaker());
	}

In this example is the data in base guaranteed to exist? Or is 
base definitely part of the allocation of Child on the heap?


More information about the Digitalmars-d-learn mailing list