In the code below, c_p must be storing the address of derived class object. Please explain why comment 1. prints "base" and, 2. prints "derived".
class C{
private:
int a;
C *c_p;
public:
virtual void print(){
cout << "base";
};
C(int x): a(x), c_p(this){
//1.
c_p->print();
}
void print_data(){
c_p->print();
}
};
class S : public C{
private:
int b;
public:
void print(){
cout << "derived";
}
S(int x ,int y): C(x), b(y){}
};
int main(){
S s_o(5, 3);
//2.
s_o.print_data();
cout << "Hello, world\n";
return 0;
}