0
class A
{
    virtual void funcion()
    {
        //...
    }
}
class B:public A
{
     //1:virtual void function();
     //2:void function();
}

What's the differences between the 1 and 2 ? Or it is the same?

samsara
  • 41
  • 1
  • 8

2 Answers2

4

They're the same. A function declared virtual in the base class is virtual all through the inheritance chain.

I find it useful to add the virtual for clarity (more often than not, the classes aren't in the same file).

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
2

They're exactly the same. Once a function has been declared virtual in a base class, any class that inherits from it will also have that function declared virtual by default.

Yuushi
  • 25,132
  • 7
  • 63
  • 81