[C++-sig] call_f(Derived) did not match C++ signature
aashish at iastate.edu
aashish at iastate.edu
Wed Jun 9 16:52:11 CEST 2004
I think what you are doing wrong is instead of passing the object of
Derived you are passing the class itself
do this:
from test_foo import *
class Derived(Base):
def f(self):
return 42
derived = Derived()
print derived.f()
print call_f(derived)
------------------------------------
and in C++
#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;
};
BOOST_PYTHON_MODULE(test_foo) {
class_<Base, BaseWrap, boost::noncopyable>("Base") ;
def("call_f", call_f);
}
---------------------------------
if you look carefull the call_f takes the ref to Base ...
Hope this helps,
~aashish
>/doc/class_virtual_functions.html
>
> But I have a problem ...
> I compiled this example as module foo and ran test_foo.py
> attached to this mail.
> Then I had following errors:
>
> ====== BEGIN OUTPUT ======
> *****************************************************************
> Failure in example: foo.call_f(a)
> from line #9 of test_foo
> Exception raised:
> Traceback (most recent call last):
> File "/home/shin/.local/lib/python2.3/doctest.py", line
> 442, in _run_examples_inner
> compileflags, 1) in globs
> File "<string>", line 1, in ?
> ArgumentError: Python argument types in
> foo.call_f(Derived)
> did not match C++ signature:
> call_f(Base {lvalue})
> *****************************************************************
> 1 items had failures:
> 1 of 4 in test_foo
> ***Test Failed*** 1 failures.
>
> EXIT STATUS: 1
> ====== END OUTPUT ======
>
> What's wrong?
> Thanks.
>
>
>
> __________________________________________________
> Do You Yahoo!?
> http://bb.yahoo.co.jp/
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
-----------------------------------------------
Aashish Chaudhary | Email:
Research Assistant | ashish_cy at yahoo.com
Iowa State University | aashish at iastate.edu
Ames, Iowa - USA | Ph: (515) 441-1178
-----------------------------------------------
More information about the Cplusplus-sig
mailing list