I am creating a small project in c++ with the concept of inheritance and std::vector. I want to add my different clients in std::vector of Parent Class but when I call the run method, it always calls the Parent class run method not the child class run method.
#include <vector>
#include <iostream>
class IClient
{
public:
void run(){std::cout<<"Base Client Called"<<std::endl;}
};
class AFKClient : public IClient
{
public:
void run()
{
std::cout<<"AFK Client Called"<<std::endl;
}
};
class Application
{
public:
std::vector<IClient> clients;
void addClients(IClient client)
{
clients.push_back(client);
}
void run()
{
for (auto c: clients)
{
std::cout<<"calling client"<<std::endl;
c.run();
}
}
};
int main()
{
Application application;
AFKClient afkClient;
application.addClients(afkClient);
application.run();
return 0;
}