0

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?

Bob Dalgleish
  • 8,167
  • 4
  • 32
  • 42
HTron
  • 337
  • 3
  • 14

1 Answers1

2

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
}
YSC
  • 38,212
  • 9
  • 96
  • 149
  • thanks for your quick answer. I still need some time to process that information and get a grasp of what it all means.. – HTron Feb 12 '19 at 18:36