[PyKDE] sip: C++ virtual methods
Patrick Stinson
ajole-1 at gci.net
Mon Sep 22 07:14:01 BST 2003
I've been having a never-ending struggle with virtual methods. It seems that
virtual methods wrapped by sip don't always work - that is they actually end
up working like non-virtual functions. This isn't consistent, and I've never
found a solution besides fiddling with it until the _same exact_ code ends up
functioning differently after a number of print-out style debugging.
Consider this:
media = PK.CreateMediaLayer("./track.ogg")
while not media.AtEnd():
media.Read()
All of these methods are C++ wrapped methods. PK::CreateMediaLayer() returns a
PK_MediaLayer *, which may be an instance of either PK_WaveDecoder or
PK_OggDecoder. All PK_Media:Layer methods are [not pure] virtual in sip and
C++, are reimplemented in the respective subclasses, are are not inline.
In the above example, media.AtEnd() is supposed to call
PK_OggDecoder::AtEnd(), but it really calls PK_MediaLayer::AtEnd(). Why is
that? Are there certain caveats with C++ virtual functions that I have
naively overlooked? What is the relationship to methods declared virtual in
sip and those declared virtual in C++? Is virtual really needed in sip?
I hope Phil isn't the only person that will be able to answer these...
Thanks!
More information about the PyQt
mailing list