[email protected]
[Top] [All Lists]

Re: [C++-sig] exposing a private member function?

Subject: Re: [C++-sig] exposing a private member function?
From: "Roman Yakovenko"
Date: Thu, 18 May 2006 12:04:49 +0300
On 5/18/06, Naceur Meskini <[email protected]> wrote:
> The probleme is that when I expose A and B to python,
> the function A::insert is exposed because it's public and B::insert is not
> but when we are in the python side the user could use this code:
> a = A()
> a.insert(..) # that normal
> b = B()
> b.insert() # <------------ I don't want to allow that to users.

Python code:

import your_module
your_module.B.insert = \
    lambda self: raise RuntimeError( "This is a private function!
Don't call it." )

This should do the trick. The same thing could be done in C++. The
main idea is to export
function with the name "insert" but with implementation that
throws/raises an exception

> Regards.
> Naceur.

Roman Yakovenko
C++ Python language binding
C++-sig mailing list
[email protected]

<Prev in Thread] Current Thread [Next in Thread>