Prothon gets Major Facelift in Vers 0.1.0 [Prothon]

Neil Hodgson nhodgson at bigpond.net.au
Sun May 23 17:46:03 EDT 2004


gabor:

> hmmm...i understand that you can cast away const,
> but what about...
>
> class C
> {
> private x;
> };

   Technique 1:

class D {
public:
    int x;
};

   C c;
   (reinterpret_cast<D*>(&c))->x = 1;

   Technique 2:

#define private public
#include <C_definition.h>
#undef private

   C c;
   c.x = 1;

   In both of these it is obvious that the encapsulation rules are being
broken which is exactly the same situation as when someone uses the mangled
name in Python. I have used technique 2 in production code where a library
could not be altered and access to private methods was required.

   Neil





More information about the Python-list mailing list