I am learning about polymorphism in C++ and decided to implement an example. Is there anything I need to fix in my code? This compiles and runs. #include <iostream>using std::cout;using std::endl;using std::cin;class Employee{public:    Employee():salary(1000){}    virtual ~Employee(){}    virtual void Talk() const {cout << Employee says: ;}protected:    int salary;};class Programmer : public Employee{public:    void Talk() const {cout << I am a Programmer.\n;}    void Compiling() const {cout << My code is compiling...\n;}};class SalesPerson : public Employee{public:    void Talk() const {cout << I am a SalesRep.\n;}    void Selling() const {};};int main(){    const int numEmployees = 3;    Employee* Company[numEmployees];    Employee* pEmployee;    int choice,i;    for(i=0; i<numEmployees; i++)    {        std::cout << (1) Programmer (2) SalesRep: ;        cin >> choice;        if(choice == 1)            pEmployee = new Programmer;        else            pEmployee = new SalesPerson;        Company[i] = pEmployee;    }    cout << endl;    for(i = 0; i<numEmployees;i++)    {        Company[i]->Talk();        Programmer *pCoder = dynamic_cast<Programmer *> (Company[i]);        if(pCoder)            pCoder->Compiling();        cout << endl;    }    return 0;}
Single inheritance polymorphism
c++;beginner;polymorphism
Some things I noticed at once:There is something wrong in this for-loop:for(i = 0; i<numEmployees;i++){    Company[i]->Talk();    Programmer *pCoder = dynamic_cast<Programmer *> (Company[i]);    if(pCoder)        pCoder->Compiling();    cout << endl;}There is a memory leak. You need to add delete Company[i]You aren't using the Employee object polymorphically. Why are you doing this?Programmer *pCoder = dynamic_cast<Programmer *> (Company[i]);You are trying to get at a method that doesn't seem appropriate for the base class. Compiling() is a method specific to the derived class Programmer What you are doing is a bit hacky. It works because the base pointer is checked at runtime. You added an if-statement, so I assume you are at least aware. In the future, do not access methods that are specific to derived classes through the base pointer.You are using std::cout. I would keep it consistent and remove std:: fromstd::cout << (1) Programmer (2) SalesRep: ;.