#include <iostream>
class MyClass
{
public:
MyClass() {
itsAge = 1;
itsWeight=5;
}
~MyClass();
int GetAge() const { return itsAge; }
int GetWeight() const { return itsWeight; }
void SetAge(int age) { itsAge = age; }
private:
int itsAge;
int itsWeight;
};
MyClass :: ~MyClass()
{
std::cout << "Destructor called!\n";
}
int main()
{
MyClass * objectArrayPointer = new MyClass[50];
int i;
MyClass * currentPointer;
for (i = 0; i < 50; i++)
{
currentPointer = new MyClass;
currentPointer->SetAge(2*i +1);
objectArrayPointer[i] = *currentPointer;
delete currentPointer;
}
for (i = 0; i < 50; i++)
std::cout << "#" << i+1 << ": " << objectArrayPointer[i].GetAge() << s
td::endl;
delete [] objectArrayPointer;
return 0;
}
|