[C++-sig] python override of C++ virtual mem fun not exactly working yet
DRandallTaylor
DRandallTaylor at yahoo.com
Sun Apr 2 02:44:27 CEST 2006
DRandallTaylor <DRandallTaylor <at> yahoo.com> writes:
> [...]
May I rephrase?
Is conversion from a Python class to the boost::python type that it is derived
from automatic? I think it probably is, therefore I must be doing something
wrong:
class InboxListener(VIAmCallback):
def __init__(self, sess):
VIAmCallback.__init__(self)
self.inbox = sess.CreateInbox(self)
gives me:
File "test.py", line 32, in run
listener = InboxListener(sess)
File "test.py", line 10, in __init__
self.inbox = sess.CreateInbox(self)
ArgumentError: Python argument types in
VIAmSession.CreateInbox(VIAmSession, InboxListener)
did not match C++ signature:
CreateInbox(class tt_stream_ns::VIAmSession {lvalue}, class
tt_stream_ns::VIAmCallback {lvalue})
And my C++ looked like this:
struct VIAmCallbackPublic : public tt_stream_ns::VIAmCallback
{
[...]
};
struct VIAmCallbackWrap : public VIAmCallbackPublic,
python::wrapper<VIAmCallbackPublic>
{
[...]
]
python::class_ <VIAmCallbackWrap, boost::noncopyable>("VIAmCallback")
.def("OnData", &VIAmCallbackPublic::OnData,
&VIAmCallbackWrap::default_OnData);
And I thought that the Python error message above tells me that python does
NOT believe that InboxListener is actually a tt_stream_ns::VIAmCallback. So I
experimented by added a python::bases<> template template arg like this:
python::class_ <
VIAmCallbackWrap
, python::bases<VIAmCallbackPublic, tt_stream_ns::VIAmCallback>
, boost::noncopyable
> ("VIAmCallback")
def("OnData", &VIAmCallbackPublic::OnData,
&VIAmCallbackWrap::default_OnData);
And then I get a worse error from Python:
Traceback (most recent call last):
File "test.py", line 1, in ?
from pycore import *
RuntimeError: extension class wrapper for base class struct VIAmCallbackPublic
has not been created yet
Am I completely clueless or simply overlooking something. Please tell me it
is the latter.
Sincerely,
Your Faithful n00b.
DRandallTaylor
More information about the Cplusplus-sig
mailing list