difference in using virtual and not using virtual

Posted by numerical25 on Stack Overflow See other posts from Stack Overflow or by numerical25
Published on 2010-06-13T20:48:54Z Indexed on 2010/06/13 20:52 UTC
Read the original article Hit count: 187

Filed under:
|
|
|

In C++, whether you choose to use virtual or not, you can still override the base class function. The following compiles just fine...

class Enemy 
{
public:
    void SelectAnimation();
    void RunAI();
    void Interact()
    {
        cout<<"Hi I am a regular Enemy";
    }

private:
    int m_iHitPoints;
};

class Boss : public Enemy
{
public:
    void Interact()
    {
        cout<<"Hi I am a evil Boss";
    }
};

So my question is what is the difference in using or not using the virtual function. And what is the disadvantage.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c