tag:blogger.com,1999:blog-5608455.post-1085352746016281922004-05-24T00:52:00.000+02:002004-06-28T13:41:59.610+02:00Hi all, long time since my last posting.
<br />
<br />As you probably know, I'm not a C++ expert, even if I can almost read C++ code without many problems.
<br />
<br />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:
<br /><blockquote>
<br /> Technique 1:
<br />
<br />class D {
<br />public:
<br /> int x;
<br />};
<br />
<br /> C c;
<br /> (reinterpret_cast<D*>(&c))->x = 1;
<br />
<br /> Technique 2:
<br />
<br />#define private public
<br />#include <C_definition.h>
<br />#undef private
<br />
<br /> C c;
<br /> c.x = 1;
<br /></blockquote>
<br />
<br />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?<div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5608455-108535274601628192?l=vvolonghi.blogspot.com'/></div>Valentinohttp://www.blogger.com/profile/13519795655711289924noreply@blogger.com0