A
ambar.shome
Hi,
Please take a look at the code snippet given below:#include<iostream>
using namespace std;
class A
{
public:
virtual void test(){cout<<"Default implementation called"<<endl;}
};
class B
ublic A
{
private:
void test(){cout<<"Derived class called"<<endl;}
};
int main()
{
A *a = new B;
a->test();
return 1;
}
The output is :
Derived class called
Now, my question is how can I access a private function of a class from
main? I accept that I did it via dynamic polymorphism. Still, should I
be allowed to access a member function which is private?
Thanks & Regards
Ambar
Please take a look at the code snippet given below:#include<iostream>
using namespace std;
class A
{
public:
virtual void test(){cout<<"Default implementation called"<<endl;}
};
class B
{
private:
void test(){cout<<"Derived class called"<<endl;}
};
int main()
{
A *a = new B;
a->test();
return 1;
}
The output is :
Derived class called
Now, my question is how can I access a private function of a class from
main? I accept that I did it via dynamic polymorphism. Still, should I
be allowed to access a member function which is private?
Thanks & Regards
Ambar