class Base
{
    virtual void foo();
}
class Derived : public Base
{
    void foo();
}
It it OK? Or it can make some problems? I think it insist "DO NOT INHERIT FROM DERIVED".
class Base
{
    virtual void foo();
}
class Derived : public Base
{
    void foo();
}
It it OK? Or it can make some problems? I think it insist "DO NOT INHERIT FROM DERIVED".
Once you marked the foo() function in Base class as virtual it is implicitly virtual in Derived class, even if you don't mention the keyword virtual in front of it.
 
    
    virtualness is inherited. Even if you do not declare an overridden method virtual, it will be virtual.
Hence, if you access an object of Derived using Base pointer or reference, it will call foo of Derived.
 
    
    virtual functions are inherited automatically. So even if you don't declare it as virtual, it is virtual actually.
The reason for you to explicitly declare it as virtual is for better clarification so that anyone reading this code can instantly understand that it is a virtual functions, without having to check the base class declarations.
