[C++-sig] How to tell in member function exists in Python class

David Abrahams dave at boost-consulting.com
Thu Jul 28 22:56:36 CEST 2005


"Paul F. Kunz" <Paul_Kunz at slac.stanford.edu> writes:

> I have a virtual C++ base class which I"m exposing to Python so that
> derived classes can be written in Python.   Some virtual functions may
> be overriden in Python and some not.   So in my C++ class which makes
> the interface between Pyton and C++, I would like to test if the
> Python class  has implemented a member function or not.   I've done
> the following, following Dave Abrahams' advice on a previous topic...
>
> unsigned int
> FunctionWrap::
> dimensions () const
> {
>   unsigned int dims = 0;
>
>   if ( override member = this -> get_override ( "dimensions" ) ) {
>     dims = member(); // calls the Python function
>   }
>   else { // didn't override it
>     dims = FunctionBase::dimensions (); // calls the C++ base class
>   }
>   return dims;
> }
>
> This works.   But, I can't find `get_override()' in the Boost.Python
> documeenation.    Maybe I miessed it.   

http://www.boost.org/libs/python/doc/v2/wrapper.html#wrapper-spec-synopsis

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




More information about the Cplusplus-sig mailing list