Right now I feel fairly unlearned with dynamically allocating memory... even after doing so several times and doing projects that require one to dynamically allocate memory for classes and primitive types.
Basically, how does one research allocation for different scenarios such as...
#include <cstdlib>
#include <iostream>
using namespace std;
class Other
{
};
class MyClass
{
public:
int amount;
Other **other1, *other2;
MyClass(Other *ot, int size)
{
amount = size;
other2 = new Other[size];
other1 = new Other*[size];
for(int i = 0; i < size; i++)
{
other1[i] = new Other[1];
other1[i] = &ot[i];
other2[i] = ot[i];
}
}
~MyClass()
{
for(int i = 0; i < amount; i++)
{
delete other1[i];
}
delete other1;
delete other2;
}
};
int main(int argc, char *argv[])
{
Other o[5];
MyClass mc (o, 5);
mc.~MyClass();
cin.get();
return 0;
}
Is the above correct?
I've been looking through various sites for examples of how to properly deallocate memory or assign objects to pointers with allocated memory and the usual examples only include 1 pointer.
Edit: Also, what should I do when I don't have a primary void constructor when allocating memory for that object for a double pointer? What then?