Can I Allocate a Block of Memory with new?-Collection of common programming errors
Is there any reason you want to do it like in the link you provided? A little more context would help. Otherwise I would personally just use a constructor to do that:
struct myStruct {
int* arr1;
int* arr2;
myStruct(int num)
{
arr1 = new int[10];
arr2 = new int[10*num];
}
~myStruct()
{
delete[] arr1;
delete[] arr2;
}
};
int main()
{
int num = 3;
myStruct* a;
a = new myStruct(3);
delete a;
}