我已经定义了一个这样的类:
class CircularBuffer {
private:
struct entry {
uint64_t key;
int nextPtr;
int prevPtr;
int delta;
};
int head, tail, limit, degree;
entry *en;
public:
CircularBuffer(int a, int b)
{
limit = a;
head = 0;
tail = limit -1;
degree = b;
en = new entry[ limit ];
for (int i=0; i<limit; i++) {
en[i].key = 0;
en[i].delta = 0;
en[i].nextPtr = 0;
en[i].prevPtr = 0;
}
};
~CircularBuffer() { delete [] en; }
};
在另一个文件中,我包含了这个类(头文件)
#include "circular.h"
class foo {
CircularBuffer cb;
foo() {} //ERROR LINE
void initialize() {
cb = new CircularBuffer(10, 2);
}
};
但是,这有错误说:
error: no matching function for call to ‘CircularBuffer::CircularBuffer()’
note: candidates are: CircularBuffer::CircularBuffer(int, int)
note: CircularBuffer::CircularBuffer(const CircularBuffer&)
它迫使我这样做:
#include "circular.h"
class foo {
CircularBuffer cb;
foo()
: cb( CircularBuffer(10, 2) )
{}
void initialize() {}
};
但是我不想要第二个实现。我要第一个。我该如何解决?