Inside a class BaseClass I have a public function:
virtual void Call(){};
Inside of a derived class Archer I have the function:
void Call(){ cout << "whatever" << endl; };
I also have a vector set up:
vector<BaseClass> classes;
wherein I push 3 classes derived from BaseClass. The problem seems (to me, I'm probably wrong) to be that I am calling Call() from a reference to BaseClass even though I push them into the vector through a method like:
BaseClass Player::CharChoice(string character)
{
if(character == "Archer") return *new Archer();
else if(character == "Knight") return *new Knight();
else if(character == "Sorcerer") return *new Sorcerer();
else cerr << "CHARACTER NOT DEFINED" << endl;
};
for(int c = 0; c < chars.size(); c++)
{
classes.push_back(CharChoice(chars[c]));
}
If I instead set up a variable such as:
Archer *archer = new Archer();
and call Call(), it works how I would intend. I'm fairly new to C++ and cannot think up a solution to this.