Can somebody please explain why is the output of the following code is B:2 ? How does the variable x get the value of num when there is no call to A::print(int)
#include <iostream>
class A
{
  public:
    void virtual print(int num = 2) {
         std::cout << "A:" << num << std::endl;
    }
};
class B : public A
{
  public:
    void virtual print(int x = 22) {
        std::cout << "B:" << x << std::endl;
    }
};
int main()
{
    A *a = new B;
    a->print();
    delete a;
    return 1;
}
