c++-sig@python.org
[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 <Naceur.Meskini@xxxxxxxxxxxxxxx> 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
http://www.language-binding.net/
_______________________________________________
C++-sig mailing list
C++-sig@xxxxxxxxxx
http://mail.python.org/mailman/listinfo/c++-sig

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