I have a base class character, a child class pacman, and a file called manager.cpp which contains main and serves to manage the characters in the game while the game is in progress.
In Character.h I have declared desiredDirection and its mutators and accessors as follows:
In manager.cpp I have declared pacman to be a global variable as follows (I know global variables are naughty but I haven't thought of the best way to manage the characters yet so its temporary):
void setDirection(int newDirection);
const int getDirection() const;
void setDesired(int newDirection); //set desired direction
const int getDesired() const;
int direction; //current direction
in the same file (manager.cpp), I need to access pacman's desiredDirection and I do it as follows:
#include <string> //might be able to remove later - here for debugging
using namespace std;
Pacman * pacman;
before I had this working by having desiredDirection as a global variable in Manager.cpp but I'm trying to avoid using global variables. When I compile my program I get:
void Timer(int extra)
if (pacman->getDesired() == 4)
manager.cpp(43) : error C2248: 'Character::getDesired' : cannot access protected member declared in class 'Character'
character.h(38) : see declaration of 'Character::getDesired'
character.h(15) : see declaration of 'Character'
I'm guessing the only way I can use the getters and setters is if I used them within pacman's implementation file? So, if I need access in manager.cpp, what would be the best way to do it?