خرید بک لینک

Vote count: 0

class Animal
{
public:
    void speak()
    {
        cout << "Animal Speak" << endl;
    }

    virtual void walk()
    {
        cout << "Animal Walk" << endl;
    }
};

class Lion:public Animal
{
public:
    void speak()
    {
        cout << "Lion Speak" << endl;
    }

    void walk()
    {
        cout << "Lion Walk" << endl;
    }

    void roar()
    {
        cout << "Lion roar" << endl;
    }
};

int main()
{
    Animal* pAnimal = new Lion();
    pAnimal->speak();
    pAnimal->walk();    
    delete pAnimal;
}

Here output is: Animal Speak Lion Walk.

In this case the object made is of Lion class. So why does Animal's speak function is called? Can any one explain what happens at compiler level?

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 4 مرداد 1395 ساعت: 15:36

صفحه بندی