#include <iostream>
using std::cout;
using std::endl;
class Test {
int *cp, length;
public:
Test(int _length)
{
cout << "Constructor" << endl;
length = _length;
cp = new int[length];
for (int i = 0; i < length; i++)
cp[i] = i * 2;
}
~Test()
{
cout << "Destructor" << endl;
delete[] cp;
cp = NULL;
}
void print()
{
for (int i = 0; i < length; i++)
cout << cp[i] << endl;
}
};
int main()
{
Test *p = new Test(4);
p->print();
delete p;
return 0;
}
/*
run:
Constructor
0
2
4
6
Destructor
*/