I have created a class template that holds a union of the following type, which should be of variable length.
union BufferUnion {
int buf32;
short buf16[2];
};
class SomeClass {
int nBufs;
int buflen;
BufferUnion **bu;
SomeClass(int nBufs, int buflen);
~SomeClass();
}
and now I want to dynamically allocate a few of these buffers in the .cpp file, but I am getting a read violation when trying to call the constructor.
SomeClass::SomeClass(int nBufs, int buflen)
{
this->nBufs = nBufs;
this->buflen = buflen;
for (int i=0; i < nBufs; ++i) {
bu[i] = new BufferUnion[buflen];
}
}