Thread overview
Using static opCall instead of the default constructor.
Jul 16, 2013
Jaehunt
Jul 16, 2013
Namespace
Jul 17, 2013
Jaehunt
July 16, 2013
Hello, I am trying to using static opCall instead of the default constructor.

When I run it, I got "Error: need 'this' to access member A".

How to fix it?

Here is my code.

struct PriorityQueue(T) {
	static const int DEFAULT_QueueSIZE = 1;
	T[] A;
	int num;
	
	this(this){
		A = A.dup;
	}
	
	static PriorityQueue opCall() {
		
		A =  new T[DEFAULT_QueueSIZE];  // Error
		num = 1;                        // Error
		
		PriorityQueue priorityQueue;
		
		return priorityQueue;
	}
	
	bool empty() { return num == 0; }
	
	void insert( T item) {
		if( A.length == num ) A.length *= 2;
		A[ num++] = item;
	}
	
	T extractMax() {
		A.sort;
		return A[ --num];
	}
}
July 16, 2013
----
static PriorityQueue opCall(T)() {
	PriorityQueue!T po;

	po.A = new T[DEFAULT_QueueSIZE];
	po.num = 1;

	return po;
}
----
July 17, 2013
On Tuesday, 16 July 2013 at 23:00:06 UTC, Namespace wrote:
> ----
> static PriorityQueue opCall(T)() {
> 	PriorityQueue!T po;
>
> 	po.A = new T[DEFAULT_QueueSIZE];
> 	po.num = 1;
>
> 	return po;
> }
> ----

Thanks a lot.