On May 3, 9:25 am, Shraddha <shraddhajosh...@gmail.comwrote:
Is it is possible to derive pivate class members of base class in it's
derive class?
No, according to the c++ design there is no explicit mechanism to
derive a private member of a base class.
But (yes the inevitable but... :) ) if you want to access the private
data in a derived class there are whole lot of methods to do that.
Remember access specifiers are a design decision and not a security
constraint.
one of the method would be :
class base {
private:
int b;
int a;
public:
base()
{
b=100;
a= 200;
}
};
class derived :public base{
public:
void print()
{
printf("%d\n", *this);
printf("%d\n", *(reinterpret_cast<int*>(this)+1));
}
};
int main ()
{
derived o2;
o2.print();
return 0;
}
Gangs.