I have the following code:
#include <string>
#include <iostream>
class A{
public:
    virtual void print() {std::cout << "A" << std::endl;};
};
class B : public A{
public:
    void print() {std::cout << "B" << std::endl;};
};
int main(){
    A* a1;
    a1 = new B;
    B b;
    A a2 = b;
    a1->print();
    a2.print();
    std::string s2;
    std::getline (std::cin,s2);
}
And the output that it produce is
B
A
Now, why it the derived method called when the object is a pointer and the base method when the object is not?
