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];
}
}