| Thread overview |
|---|
July 16, 2013 Using static opCall instead of the default constructor. | ||||
|---|---|---|---|---|
| ||||
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 Re: Using static opCall instead of the default constructor. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jaehunt | ----
static PriorityQueue opCall(T)() {
PriorityQueue!T po;
po.A = new T[DEFAULT_QueueSIZE];
po.num = 1;
return po;
}
----
| |||
July 17, 2013 Re: Using static opCall instead of the default constructor. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Namespace | 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.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply