Valentino Volonghi's Weblog

Greetings mercenaries!

Monday, May 24, 2004

Hi all, long time since my last posting.

As you probably know, I'm not a C++ expert, even if I can almost read C++ code without many problems.

One thing that I didn't know is that encapsulation is not that strong as it is belived to be, there are 2 techniques that enable you to access all attributes inside a class and I'm going to show you:

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;


This is just to say that Python is not the only one that plays some tricks instead of having real private attributes/methods. But again who really needs private methods?