[C++-sig] virtual overrides and custom smart pointers
Leonard "paniq" Ritter
paniq at paniq.org
Sun Apr 17 15:01:40 CEST 2005
hi,
i'm running into a problem i'm trying to fix since several days without
much luck. it seems my custom smart pointer class becomes worthless when
wrapper<> is used to construct an object whose methods can be overridden
in python.
wrapper export code:
class_<WindowEventsWrap, bases<Mu::Interface::Unknown>,
Ptr<WindowEventsWrap>, boost::noncopyable>("WindowEvents")
.def("OnWidgetEvent",pure_virtual(&WindowEvents::OnWidgetEvent))
.def("WidgetEventHandled",pure_virtual(&WindowEvents::WidgetEventHandled))
;
wrapper declaration:
struct WindowEventsWrap
: InterfaceImplementation<WindowEventsWrap,
Implements<Mu::Sandoz::Interface::WindowEvents> >,
wrapper< Mu::Sandoz::Interface::WindowEvents >
python test code:
class MyWindowEvents(Sandoz.WindowEvents):
def OnWidgetEvent(self, event):
print event.type
return Sandoz.Result.NotImplemented
def WidgetEventHandled(self, event, widget):
print event.type, widget
return Sandoz.Result.NotImplemented
def Main():
mwe = MyWindowEvents()
view = Sandoz.ViewFrame("µ.Sandoz.ViewFrame")
view.Connect(mwe)
del mwe
connect adds a reference to the mwe callback object and view calls that
object later on. this is known to work. however when i delete mwe right
after Connect(), the object itself persists, but its overridden methods
(and i guess the underlying python object as well) are gone. no Release
or AddReference on my object is called from wrapper_base, so i assume it
is not using my custom smart pointer class which deals with this stuff.
can someone suggest a solution to this problem?
best regards,
leonard
More information about the Cplusplus-sig
mailing list