This seems fairly easy, but I'm having a tough time accessing a class through pointers at any point in the code.
The project is an easy pet simulator, much like a tamigochi. I am trying to feed my pet through a function. I realize I can access the object from the source code and forget the function all together, but I would like to learn how this works before I go ahead.
How I think it works is that I need to pass the address of the pet object to the function, have the function make a pointer variable to that address, and have the code alter the variables in that object through the address.
In a case statement for user input, I have, under case 1 (Press 1 to feed pet)
Code:
void feedPet(beast *pet);
And here is the function itself.
Code:
void feedPet(beast newPet) {
int * pNewPet = &newPet;
cout << "You have fed your pet 10 pieces of food ";
*pNewPet->eat();
return;
}
and the functions prototype:
Code:
void feedPet(int &pointer);
If there is a phrase to explain what I am doing, I'd be willing to look it up. But at the moment, I have no clue what I should be looking up