dcollections ArrayList pb with mixin template

Steven Schveighoffer schveiguy at yahoo.com
Thu Jul 1 13:59:23 PDT 2010


On Thu, 01 Jul 2010 15:36:53 -0400, BLS <windevguy at hotmail.de> wrote:

> Hi, I have a problem with a mixin template. More exact with an  
> Arraylist!T within a mixin template.
> Given.
> void main() {
> 	auto p = new Person("Hans", 32);
> 	p ~= new Person("Steve", 40);
> 	p ~= new Person("Bjoern", 101);
> }	
>
> class Person {
> 	private	string _name;
> 	private uint _age;
> 	
> 	mixin TLinkList;
> 	
> 	this(string name, uint age) {
> 		this._name = name;
> 		this._age = age;
> 	}
> }
> 	
> mixin template TLinkList() {
> 	alias typeof(this) T;
> 	alias ArrayList!T TList;
> 	
> 	T[] pa;
> 	auto pl = new TList(pa);  // This does not work !
> 	void opCatAssign(T v) {
> 		pa ~= v;
> 	}	
> }
> Error: non-constant expression new ArrayList(pa)	main.d	
>
> Ideas ?
> Thanks Bjoern

I'm thinking it has to do with you trying to create a member with that  
line.

I think a member initializer has to be a constant expression, like int i =  
1.  Anything else has to be done in the constructor.  This kinda sucks,  
because you can't initialize members with their defaults where you declare  
them, but it's the way D works.

-Steve


More information about the Digitalmars-d-learn mailing list