Can there be any distinction between proclaiming inherited virtual function inside a child class with the "virtual" keyword or otherwise, thinking about I wish to call fun appropriate to my objects' type. Consider the comments.

#include <cstdio>
struct A{
    int a;
    virtual int fun(){return a+1;}
struct B: public A{
    virtual int fun(){return a+5;} //I put virtual here
//  int fun(){return a+5;} // Any difference if I put virtual before or not?
int main(){
    B obj;
    printf("%d\n", static_cast<A>(obj).fun()); // A::fun() called. Why?
    printf("%d\n", static_cast<A&>(obj).fun()); // B::fun() called. As expected
    printf("%d\n", static_cast<A*>(&obj)->fun()); // B::fun() called. As expected
    printf("%d\n", static_cast<A>(B()).fun()); // A::fun() again. Why?
//  printf("%d\n", static_cast<A&>(B()).fun()); //invalid_cast error. Why? 
    printf("%d\n", static_cast<A*>(&B())->fun()); //It works! B::fun() call
    return 0;

Overriding functions in derived courses are unconditionally declared "virtual" when the corresponding function within the base class is virtual. Just make certain you have the identical signature, or you will unintentionally hide the initial function and declare a replacement!

In C++0x, you can make liberal utilisation of the override specifier.

Your two "Why?" questions are due to slicing you are making new, copy-sliced objects of type A. Observe that in B x; static_cast<A>(x); the cast is equivalent to saying A(x).

Keeping the virtual key phrase prior to the overridden member function within the derived class is optional. Run-time polymorphism works just for pointers or references.