Calling private base methods

Duncan Booth duncan.booth at invalid.invalid
Fri Apr 13 03:30:39 EDT 2007


"7stud" <bbxx789_05ss at yahoo.com> wrote:

>> Really, it does work (probably). There are other ways to get at private
>> members in C++ but this is the easiest.
> 
> I can also access private methods of a class if my sister backspaces
> over "private" and types "public" instead.
> 
> In your example, no private methods were ever created, and therefore
> you are not accessing private methods.
> 
Are you being deliberately obtuse? The methods are private throughout the 
program *except* for the one source file where you do this trick.

It won't work if the compiler mangles the protection into the name, but I 
have used this successfully with a C++ library where I absolutely couldn't 
do what I needed without getting at a private method. The fact that I had 
to resort to this trick is a big indication of course that genuinely 
private members (as opposed to a 'keep off' naming convention) are a bad 
idea in general.

If the name does get mangled then you may of course have to do other much 
messier tricks to get at the address of the function and then call it.



More information about the Python-list mailing list