在C ++类中实现TPCircularBuffer

问题描述 投票:0回答:1

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

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

#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'复制构造函数

我不明白?

c++ signal-processing audiokit the-amazing-audio-engine
1个回答
2
投票

由于TPCircularBuffer有一个volatile数据成员,它是非常不可复制的。这使您的班级非常不可复制。

如果你需要在MyClass上复制语义,你需要提供自己的复制构造函数:

MyClass(MyClass const& other) : // ...
{
    TPCircularBufferInit(&cbuffer, 2048); // doesn't copy anything, but you might want to
}
© www.soinside.com 2019 - 2024. All rights reserved.