[Exceptional C++ Style] Re: [Exception C++ Style] Item 15 - UsesandAbuses of Access Rights
Paul Grenyer
paul at paulgrenyer.co.uk
Tue Dec 14 09:27:05 EST 2004
Hi
> > The Pickpocket attempts to change the meaning of the
> > class definition by redefining private as public:
> >
> > #define private public
> >
> > However, the above is illegal as it attempts to
> > redefine a keyword. It also breaks the ODR and
> > therefore the same thing applies as was stated
>
> A lighter version of this pickpocket would use
>
> #define private friend class MyClass; private
> #include "x.h"
> #undef private
>
> That IMHO leaves less chance for the compiler to break anything -- and if
> done everywhere not even breaks the ODR. As the #define for is considered
> harmless this should be similar.
I'm shocked! Why are you even contemplating this? Sure it's just plain evil?
Anyway, what about if your class had more than one private section? I
suspect it doesn't matter, but on at least one compiler I can think of I
think you'd get a warning.
I have to be honest, until I read this item I had never thought of doing any
of the things it explores. Possibly it may do more harm than good....?
Regards
Paul
Paul Grenyer
email: paul at paulgrenyer.co.uk
web: http://www.paulgrenyer.co.uk
articles: http://www.paulgrenyer.dyndns.org/articles/
Darrell "Dimebag" Abbott will be sorely missed.
More information about the Effective-cpp
mailing list