I want to know the logic behind how are we getting access to the private member function in Child class.
#include<bits/stdc++.h>
using namespace std;
class Parent{
public:
virtual void secret(){};
};
class Child:public Parent
{
string name;
void secret(){
cout << "Cant Access this";
}
public:
Child(string name):name(name){}
};
int main()
{
Child c("Whatever");
Parent* ptr = &c;
ptr->secret();
return 0;
}
Output: Cant Access this
Regards,