Perhaps this is a candidate for a one-line answer. I would still know about it.
I am writing a simple circular buffer and for some reasons that are not important for the question that I need to implement using an array of doubles. In fact, I did not invest other ways to do this, but since an array is required, I did not spend much time searching for alternatives.
template<typename T>
class CircularBuffer
{
public:
CircularBuffer(unsigned int size);
~CircularBuffer();
void Resize(unsigned int new_size);
...
private:
T* buffer;
unsigned int buffer_size;
};
Since I need to have a dynamic buffer size, buffer_size is neither a constnor a template parameter. Now the question is:
During construction and in the function, Resize(int)I require that the size be at least one, although a size buffer of one is actually no longer a buffer. Of course, using a simple double would be more appropriate, but in any case.
- - . , ? , , delete[] buffer;, , , , buffer = new T[0], delete[] delete buffer; ( )?
,
Arne