Ok, so I'm making a program in c++ that keeps track of the number of objects you make for a specific class. It works, but I added a part to change the screen output at a specific number of objects and that's where it broke.... heres the program:
#include <iostream.h>
class Cat
{
public:
Cat(int age):itsAge(age){HowManyCats++; }
virtual ~Cat() { HowManyCats--; }
virtual int GetAge() { return itsAge; }
virtual void SetAge(int age) { itsAge = age; }
static int HowManyCats;
private:
int itsAge;
};
//static member data defined
int Cat::HowManyCats = 0;
int howManyCatsFunction()
{
char phrase1;
if(Cat::HowManyCats == 1)
{
phrase1 = 'There is';
}
else
{
phrase1 = 'There are';
}
cout << phrase1
<< Cat::HowManyCats << " cats alive!"
<< endl;
}
int main()
{
const int MaxCats = 5; int i;
Cat *CatHouse[MaxCats];
for (i = 0; i<MaxCats; i++)
{
CatHouse[i] = new Cat(i);
}
for (i = 0; i<MaxCats; i++)
{
howManyCatsFunction();
cout << "Deleting the one which is ";
cout << CatHouse[i]->GetAge();
cout << " years old\n";
delete CatHouse[i];
CatHouse[i] = 0;
}
system("PAUSE");
return 0;
}