突破private的方法:
=====================================
对于private变量:
方法一:
class Y
{
public:
Y(int y=0):m_n(y){};
int getInt(){return m_n;}
private:
int m_n;
};
Y y(34);
cout<<y.getInt()<<endl;
int* pi=(int*)(&y);
*pi=347;
cout<<y.getInt()<<endl;
方法二:
int tmp;
__asm
{
mov eax,y.m_n
mov tmp,eax
add y.m_n,5
}
cout<<tmp<<' '<<y.getInt()<<endl;
========================================
对于private函数:
class C1
{
public:
virtual void test()
{
cout<<"public C1::test()"<<endl;
}
};
class C2: public C1
{
private:
virtual void test()
{
cout<<"private C2::test()"<<endl;
}
};
C2 c2;
C1 * pC1=&c2;
pC1->test();
方法二:
class O;
typedef void (O::*pO)();
class O
{
public:
static pO getFunTest()
{
return &O::test;
}
private:
void test()
{
cout<<"this is a private function of class O:test()"<<endl;
}
};
pO pp=O::getFunTest();
O o;
(o.*pp)();