I have looked for the solution to the problem below all over the internet. Some of the solutions given are exactly what I am doing, yet I am still getting an error when I try to compile my code. Any help would be greatly appreciated.
I have a base class Stats that every monster class in my code will be derived from. Here is the base class:
#include <iostream>
class Stats {
private:
int hitpoints;
int armor;
int bonus;
public:
int getHP(){return hitpoints;}
int getArm(){return armor;}
int getBonus(){return bonus;}
Stats();
Stats(int, int, int);
};
Stats::Stats() {
hitpoints = 0;
armor = 0;
bonus = 0;
}
Stats::Stats(int hp, int arm, int bon) {
hitpoints = hp;
armor = arm;
bonus = bon;
}
Now I have a monster class (here Orc), that is derived from the Stats class. The constructor of the monster class also calls the overloaded constructor of the Stats class:
#include <iostream>
#include "Stats.cpp"
class Orc: public Stats {
public:
Orc();
};
Orc::Orc() : Stats(8, 3, 1) {}
In the main function I build a new Orc object and try to call the base class function Stats::getArm() with the object:
int main() {
Orc mork();
std::cout << "Armor: " << mork.Stats::getArm() << "\n";
}
I expect to have the function return the int value for armor. Instead I am getting the error:
error: request for member 'Stats:: getArm' in 'mork', which is of a non-class type 'Orc()'
By the way, I am compiling in c++11.