Hi all,
I've got a base class Character and a class Pacman derived from Character.
Character is defined as follows:
Code:#ifndef CHARACTER_H #define CHARACTER_H #include <iostream> #include <string> #include "Position.h" enum STATE { DEAD = 0, ACTIVE = 1, SUPER = 2 }; //Speed definitions const double NORMAL = 1.0; const double SLOW = 0.5; class Character { public: Character(); Character(std::string name, Position position, int state, double speed); virtual ~Character(); virtual void move(); virtual void draw(); private: std::string name; Position position; int state; // i.e. dead, active, super double speed; }; #endifand Pacman is defined as follows:Code:#include "Character.h" using namespace std; Character::Character() : name(""), position(Position()), state(ACTIVE), speed(NORMAL) {} Character::Character(std::string name, Position position, int state, double speed) : name(name), position(position), state(state), speed(speed) {} Character::~Character() {}
and the compiler is giving me the following error:Code:#include "Pacman.h" using namespace std; Pacman::Pacman() : Character(), pillsTaken(0) { position.setX(STARTING_XPOSITION); position.setY(STARTING_YPOSITION); } Pacman::Pacman(string name, Position position, int state, double speed, int pillsTaken) : Character(), pillsTaken(0) { position.setX(STARTING_XPOSITION); position.setY(STARTING_YPOSITION); }
c:\users\...\arcade\pacman.cpp(8) : error C2248: 'Character:: position' : cannot access private member declared in class 'Character'
c:\users\...\arcade\arcade\character.h(32) : see declaration of 'Character:: position'
c:\users\...\arcade\character.h(22) : see declaration of 'Character'
I thought that since Pacman is a child of Character, it will have its own copies of private attributes defined in Character. Is this not the case?



LinkBack URL
About LinkBacks



