I now realize why pointers are so important. While sitting there for a while, trying to think of a way to work out a problem, I thought of an idea.
My problem:
In my RPG, I wanted a different enemy object to be created each time you defeat one enemy. This would mean having to create many different objects. How on Earth would I make so many hundreds of functions without given myself a hear-attack, and at the cost of TONS of memory? OMG! Pointers! Yay!
It's so obvious now:
When a new enemy is created:
Code:
...
Enemy Accessor;
int EHPX = Accessor.GetEHP(); // Not global, BTW.
int EATTX = Accessor.GetEAtt();
Enemy * BadGuy = new Enemy(EHPX,EATTX);
...
Those are passed to the constructor:
Code:
Enemy::Enemy(int a, b)
{
EHP = a;
EAtt = b;
}
Then, when the enemy is defeated:
Code:
...
BadGuy->SetEHP(1); //strengthens enemy
BadGuy->SetEAtt(1); //strengthens enemy
delete BadGuy;
...
Yay! I just use the object once, make it stronger after it dies, and then throw it away! When you encounter another enemy, another one is created, slightly stronger, and the process starts over.
Yay for pointers!