HTron
HTron

Reputation: 366

Implementing TPCircularBuffer in C++ Class

I am trying to implement a circular buffer in my class.

If I initiate it in the init method, it works, but I wanna declare the buffer variable under private, so I can access it from anywhere inside the class:

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

Doing this leads to the following compiling error: Call to implicitly-deleted copy constructor of 'MyClass'

I don't understand?

Upvotes: 0

Views: 163

Answers (1)

YSC
YSC

Reputation: 40060

Since TPCircularBuffer has a volatile data member, it is trivially non-copiable. This makes your class trivially non-copiable.

If you need copy semantics on MyClass, you need to provide your own copy constructor:

MyClass(MyClass const& other) : // ...
{
    TPCircularBufferInit(&cbuffer, 2048); // doesn't copy anything, but you might want to
}

Upvotes: 2

Related Questions