This is Homework.
I have been working on a tournament program. Currently the tournament class gets user input and instantiates a player class and a game class. The game class then calls the board class where it instantiates a boardconfig class object. At this point Is where I get my problem.
the boardconfig class is a grandparent to the boardconfig_level class which is parent to the boardconfig_level_basic class.
Grandparent class has the following method:
protected int getDimension() { return 0; }
Parent class has the following methods
protected void intiMineArray(); //defined in parent.cpp
protected virtual int getDimension() {return 0; }
private bool checkValues(); //defined in parent.cpp
Child Class has:
protected int getDimension () {return 6;}
The problem is when the constructor for the child class is called, it call s parent::initMineArray(). This method then calls the Parent::checkValues() which finally calls getDimension(). My problem is instead of calling the child::getDimension(), it calls the parent getDimension which always returns 0 instead ocalling child::getDimension.
What am I doing wrong?
void boardconfig_level::initMineArray() {
if (this->checkValues()){
//do really cool things here
}
//JR throw error here
}
bool boardconfig_level::checkValues() {
//this seems to fail although child::getDimension returns number bigger than 1
if (this->getDimension() < 1) {
cout << "Invalid Board Dimension" << this->getDescription() << endl;
return false;
}
return true;
}
boardconfig_level_basic::boardconfig_level_basic() {
this->initMineArray();
}