#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;
};
int main()
{
MyClass * myObject[50];
int i;
MyClass * objectPointer;
for (i = 0; i < 50; i++)
{
objectPointer = new MyClass;
objectPointer->SetAge(2*i +1);
myObject[i] = objectPointer;
}
for (i = 0; i < 50; i++)
std::cout << "#" << i+1 << ": " << myObject[i]->GetAge() << std::endl;
for (i = 0; i < 50; i++)
{
delete myObject[i];
myObject[i] = NULL;
}
return 0;
}
#1: 1
#2: 3
#3: 5
#4: 7
#5: 9
#6: 11
#7: 13
#8: 15
#9: 17
#10: 19
#11: 21
#12: 23
#13: 25
#14: 27
#15: 29
#16: 31
#17: 33
#18: 35
#19: 37
#20: 39
#21: 41
#22: 43
#23: 45
#24: 47
#25: 49
#26: 51
#27: 53
#28: 55
#29: 57
#30: 59
#31: 61
#32: 63
#33: 65
#34: 67
#35: 69
#36: 71
#37: 73
#38: 75
#39: 77
#40: 79
#41: 81
#42: 83
#43: 85
#44: 87
#45: 89
#46: 91
#47: 93
#48: 95
#49: 97
#50: 99