[C++-sig] Protected virtual Functions with default implementation

Roman Yakovenko roman.yakovenko at gmail.com
Mon Mar 23 20:48:02 CET 2009


2009/3/23 Renato Araujo <renatox at gmail.com>:
> Hi Roman

Good evening.

> The problem is that: How export this class?
>
> namespace geometry{
>
> class point_t
> {
> public:
>    point_t() {};
>
> protected:
>    virtual bool ret_bool() { return false; }
> };
>
> }
>
> I put attached the Py++ genereted code and a small test.
> My  question is, how export this protected virtual function? the way
> used in Py++ not work in this case.

Now I understand.

It is not possible to export protected virtual function and to be able
to call it from Python. If I am wrong, let me know and I'll update
Py++.
Previous version of Py++ allowed to do this, but than I ported it to
GCC 4.3 and MSVC 8.0 and found out that the used trick was illegal in
C++.

In many cases, protected virtual function are used in "template
method" design pattern. Py++ supports this usage and allows users to
(re)define those functions in Python.

If you need to access such functions directly, you will have to create
new class in hierarchy, which provides access to the desired
functionality.

HTH

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/


More information about the Cplusplus-sig mailing list