How do I define a typedef for a fixed length array so that I can also ‘new’. The following does not work:
typedef double Vector[3];
Vector *v = new Vector; // does not compile
We are trying to wrap into C++ some old C code which handles float * and float (*)[3] in a generic way.
The pointer to an
double[3]isdouble *– so this will work:But I suggest you don’t use it that way – to delete the array you need the array-delete-operator:
But on
new Vectoryou don’t see it is an array and so it might be forgotten.This case is handled (and strongly recommended to avoid) in Scott Meyers Effective C++. So better don’t use an typedef here.