How to access private data members outside the class without making “friend”s? [duplicate]

Here’s a way, not recommended though class Weak { private: string name; public: void setName(const string& name) { this->name = name; } string getName()const { return this->name; } }; struct Hacker { string name; }; int main(int argc, char** argv) { Weak w; w.setName(“Jon”); cout << w.getName() << endl; Hacker *hackit = reinterpret_cast<Hacker *>(&w); hackit->name … Read more

How to access private methods without helpers?

If there is extended RTTI info generated for the class private members – fields and/or methods you can use it to gain access to them. Of course, accessing through RTTI is way slower than it was through class helpers. Accessing methods: var Base: TBase2; Method: TRttiMethod; Method := TRttiContext.Create.GetType(TBase2).GetMethod(‘UsefullButHidden’); Method.Invoke(Base, []); Accessing variables: var Base: … Read more

How to make a real private instance variable?

You can use the @private keyword inside the {} to make all subsequent variable declarations private. The default visibility is @protected (which is similar to protected in Java) and that generally works well. You’d have to specifically declare a variable as @public for it to be directly accessible outside the class. This Apple documentation has … Read more