Possible Replicates:
C++ : implications of making a method virtual
Why is 'virtual' optional for overridden methods in derived classes?

I question, what's recorded behavior within the following situation:

You've

class A
{
 virtual void A()
 {
   cout << "Virtual A"<<endl;
 }
 void test_A()
 {
   A();
 }
}

class B: public A
{
  void A()
  {
   cout << "Non-virtual A in derived class"<<endl;
  }

  void test_B()
  {
    A();
  }
}

A a; B b;
a.test_A();
b.test_A();
b.test_B();

What it really designed to do based on C++ standard and why? GCC works like B::A can also be also virtual.

What shoudl take place in general whenever you override virtual method by non-virtual one out of derived class?

The sub-class member function is unconditionally virtual if your virtual base-class member function with similar title and signature is available.

The code shouldn't compile while you cannot title a technique using the title from the class. But regarding things i understand that's your big issue:

Will creating a method virtual signify exactly the same method in most the derived classes is virtual even when the virtual keyword isn't present?

The reply is yes. When a technique is declared virtual inside a class, then all overrides of this method is going to be virtual, and also the virtual keyword is optional in derived classes (even when I suggest typing it, if perhaps for documentation reasons). Observe that for any method inside a derived class to become an override it needs to have a similar title and signature, with only potential difference as being a covariant return type:

struct A {};
struct B : A {};
struct base {
   virtual A* foo();
   virtual A* bar();
};
struct derived : base {
   virtual B* foo();    // override, covariant return type
   virtual int bar();   // not override, return type is not covariant
   virtual A* bar(int); // not override, different argument list
};

Based on standard it ought to be


A a b - b

a.test_A()  //"Virtual A"

b.test_A() //Non-virtual A in derived class

b.test_B() //Non-virtual A in derived class

This code is ill-created. A constructor cannot possess a return type (as you've accomplished for the constructor of 'A'). Additionally a constructor can't be virtual.

After fixing A's constructor, class B is ill-created because the constructor of the is private.

So, you will find many issues with this code (including missing semicolons in the class definitions).