A quick clarification on virtual methods after reading Jumping int C++ by Alex Allain. If a user wanted to extend a class from someone elses library and override its methods that do not contain virtual methods; how would one call the overridden class if it is referred to by its super type
in other words how would someone override a method from someone elses library that does not have virtual keywords.
ie
something.h
Code:
#include <iostream>
namespace game{
class character{
public:
std::string getName(){return "character";}
};
}
main.cpp
Code:
#include <iostream>
#include <vector>
#include "something.h"
using std::vector
class protagonist : game::character{
public:
virtual std::string getName(){return "protagonist";}
};
class protagonist : game::protagonist{
public:
std::string getName(){return "antagonist";}
};
int main(){
vector<character*> vec;
vec.push_back(new protagonist);
vec.push_back(new antagonist);
for(vector<Character*>::iterator itr = vec.begin(),
end = vec.end();
itr!=end;
++itr){
std::printf("%s", (*itr)->getName());
delete (*itr);
cout << endl << endl;
}
vec.clear();
return 0;
}