あなたは同じビットパターンでモッククラスを作成し、
例
オリジナルクラス下のモッククラスオブジェクトに元のオブジェクトをキャストすることができ、元のクラスを参照してくださいすることができた場合は
class ClassWithHiddenVariables
{
private:
int a;
double m;
};
モッククラス
class ExposeAnotherClass
{
public:
int a_exposed;
double m_exposed;
};
あなたはメンバーを見てみたいですClassWithHiddenVariablesオブジェクトのreinterpret_castを使用してExoseAnotherClassにキャストします。
ClassWithHiddenVariables obj;
obj.SetVariables(10, 20.02);
ExposeAnotherClass *ptrExposedClass;
ptrExposedClass = reinterpret_cast<ExposeAnotherClass*>(&obj);
cout<<ptrExposedClass->a_exposed<<"\n"<<ptrExposedClass->m_exposed;
ポインタを使用してください。 –
「それはハックですか?」とはどういう意味ですか?あなたがこれを記述しているようにすると、プライベートフィールドを外部的に変更したい場合、これが完全に間違っているように思えます。 – templatetypedef
[Burt BacharachとCarole Bayer Sager](http://en.wikipedia.org/wiki/That's_What_Friends_Are_For):[これは、友人のためのものです](http://www.parashift.com/ C++ - faq-lite/friends.html)。 –