0

我正在尝试在我的班级中实现一个循环缓冲区。

如果我在 init 方法中启动它,它可以工作,但我想在私有下声明缓冲区变量,所以我可以从类内的任何地方访问它:

#import "AudioKit/TPCircularBuffer.h"

class MyClass{
public:
MyClass() { //.. 
}

MyClass(int id, int _channels, double _sampleRate)
{
   // if I uncomment the following line, it works:
   // TPCircularBuffer cbuffer;
   TPCircularBufferInit(&cbuffer, 2048);
}
private:
   // this doesn't work:
   TPCircularBuffer cbuffer;
};

这样做会导致以下编译错误: 调用“MyClass”的隐式删除的复制构造函数

我不明白?

4

1 回答 1

2

由于TPCircularBuffer具有volatile数据成员,因此它是不可复制的。这使您的课程无法复制。

如果您需要复制语义 on MyClass,则需要提供自己的复制构造函数:

MyClass(MyClass const& other) : // ...
{
    TPCircularBufferInit(&cbuffer, 2048); // doesn't copy anything, but you might want to
}
于 2019-02-12T18:21:52.743 回答