[C++-sig] Re: pure virtual methods with pyste

wiedeman at gmx.net wiedeman at gmx.net
Mon Jul 28 15:08:47 CEST 2003


Hello Dave,

sorry for the error in the posted code. This wasn't due to misunderstanding
of the tutorial, but due to copy & paste. In fact, i got the code working
with 'normal' boost.python, but wondered, why pyste doesn't provide a wrapper
for the pure virtual function a(). Here is the code:

struct Abstract {
  virtual void a() = 0;
};

#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(wrap_Test) {
  class_<Abstract, boost::noncopyable>("Abstract", no_init)
    .def("a", &Abstract::a)
    ;
}

As far as i can tell, this code works fine, and Dave Abrahams suggested to
do so in the thread he was pointing me on. Though the tutorial doesn't provide
wrappers around pure virtual functions, the above code was quite obvious -
but maybe it would be better to show how to wrap the pure virtual function f()
of class Base.

Christoph

> > Hi Nicodemus,
> >
> >>Yes, it follows the procedure in the tutorial about abstract virtual 
> >>functions, ie, it only generates the virtual wrapper. You should still 
> >>be able to override the abstract member functions in Python, though... 
> >>is this the problem you're having?
> >
> > No, that's not my problem. I want to be able to use pointers to abstract
> > classes within python without wrapping all the derived classes (in fact,
> they
> > are plugins), and, if possible, without writing a call_f function for
> every
> > pure virtual method. 
> > I've played around with boost.python and found the solution below
> > (Test.cpp). With pyste, i'd get an empty class Abstract. I wonder, if my
> solution is
> > dangerous or even wrong ?
> >
> > Thanks in advance,
> > Christoph
> >
> > /* Test.cpp */
> >
> > struct Abstract { 
> >   virtual void a() = 0;
> > };
> >
> > #include <boost/python.hpp>
> >
> > using namespace boost::python;
> >
> > BOOST_PYTHON_MODULE(myclasses) {
> >   class_<Abstract, AbstractWrap, boost::noncopyable>("Abstract")
>                      ^^^^^^^^^^^^
> This part is wrong.
> >     .def("a", &Abstract::a)
> >     ;
> > }
> 
> http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/1748053
> 
> I'm not sure why people keep doing that; perhaps we need to fix the
> tutorial somehow?  If you can, Christoph, it would be a big help if
> you could explain why you thought that was the right thing to do.
> 
> Thanks,
> Dave
> 
> -- 
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com
> 
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
> 





More information about the Cplusplus-sig mailing list