[C++-sig] Virtual methods
by Nicodemus other posts by this author
Feb 25 2003 3:45PM messages near this date
Re: [C++-sig] problem wrapping a c++ function on windows
|
Re: [C++-sig] Virtual methods
Hi!
I'm using Intel C++, STLport 4.5.3 and the current CVS.
I can't get the simple example from the tutorial about virtual methods to work.
I copied and pasted the example, but couldn't reproduce the correct behaviour in
python:
// basic.cpp
#include <boost/python.hpp>
using namespace boost::python;
struct Base
{
virtual int f() = 0;
};
int call_f(Base& b) { return b.f(); }
struct BaseWrap : Base
{
BaseWrap(PyObject* self_)
: self(self_) {}
int f() { return call_method<int> (self, "f"); }
PyObject* self;
};
// Module ======================================================================
BOOST_PYTHON_MODULE(basic)
{
class_<Base, BaseWrap, boost::noncopyable> ("Base", no_init)
;
def("call_f", call_f);
}
> >> from basic import *
> >> class Derived(Base):
... def f(self):
... return 42
...
> >> d = Derived()
Traceback (most recent call last):
File "<stdin> ", line 1, in ?
RuntimeError: This class cannot be instantiated from Python
> >>
> >> # hmmm... let's override the __init__ method and see
> >> # what happens
> >> class Derived(Base):
... def __init__(self): pass
... def f(self): return 42
...
> >> d = Derived()
> >> call_f(d)
Traceback (most recent call last):
File "<stdin> ", line 1, in ?
TypeError: bad argument type for built-in operation
> >>
I remember using this example before, and it did work... has something changed
since then?
Thanks,
Nicodemus.
_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
Thread:
Nicodemus
David Abrahams
Nicodemus
|