Say I am using an open source library of someone who does not know what they're doing well. (no encapsulation for important members) Really it's a coworker who's code I'm not allowed to modify, nor is he willing to modify it for me.
How can I forcefully access a private member without doing something like rewriting a fake class or modifying the original class?
I've tried things like #define private public
, but the class file includes some standard namespace files and this will give a compilation error.
I've tried memory manipulation, but this requires member identification which isn't going to work. (See the following)
#define PX_ACCESS_PRIVATE( pObject, _Member ) ( static_cast< std::size_t >( pObject ) + static_cast< std::size_t >( &( ( decltype( pObject )( nullptr ) )->_Member ) ) )
Any ideas?