Hello, I am creating a class that has a private array on the heap with a constructor that takes the size of the array and initializes it on the heap. Later I have to make a deconstructor delete the space and print out free after.
In my code, I was able to heap a private array and make a deconstructor, but I don't know how to take the size of the array and initialize it on the heap.
My guess is this:
int* size = new int();
Also when you initialize size on the heap, don't you also have to delete it too? If so, where, in the code, do you do that?
Class Student
{
private:
int size;
int* array = newint[size];
public:
Student(); // Constructor
~Student(); // Deconstructor
}
Student::Student()
{
// How do you make a constructor that takes the size of the array and initializes it on the heap
}
Student::~Student()
{
delete[] array;
cout << "Free!" << endl;
}