chpicker
Programmer
- Apr 10, 2001
- 1,316
I want to create a class with a member that is an array whose size is determined at runtime. Does this work to create and destroy the array? I always have trouble keeping track of pointers to arrays, arrays of pointers, and the syntax involved in each.
Code:
class MyClass {
public:
MyClass(int num);
~MyClass();
private:
int* MyArray;
};
MyClass::MyClass(int num) {
MyArray=new int[num];
}
MyClass::~MyClass() {
delete[] MyArray;
}