[C++-sig] Re: value_holder_back_reference::holds()

Niall Douglas s_sourceforge at nedprod.com
Mon Nov 3 01:47:59 CET 2003

On 2 Nov 2003 at 9:37, David Abrahams wrote:

> Instead of trying to describe it in English, please just show a small
> code example.

Like as follows:

class MainWindow(FXMainWindow):
    def __init__(self, app):
        FXMainWindow.__init__(self, app)

    def setup(self):


The point it fails at is the self.text=FXText(self) claiming that a 
MainWindow does not match C++ signature FXText(self, FXComposite *) 
despite that FXMainWindow inherits off FXComposite.

BTW I've tried making a small repeatable example. It works as 
expected and since I've no idea why the misbehaviour, it's proving 
hard to know where to go next.

> > Unfortunately find_static_type() is not finding the FXComposite and
> > is returning zero. If however I alter the "polymorphic" parameter in
> > convert_type() (called by find_static_type()) to true, it *does*
> > find the FXComposite correctly. Of course FXComposite has virtual
> > functions, therefore a virtual function table for RTTI to work with.
> That surprises me, but I guess anything is possible.

Stepping through it in the debugger, find_static_type() calls 
convert_type() (in inheritence.cpp) with src_t being a FXMainWindow, 
dst_t being a FXComposite and polymorphic=false.

It looks up src_p and dst_p fine, no problem. It then makes a 
std::pair of p & src_t and searches the cache for it. It finds an 
entry as seek.key.head becomes FXMainWindow, seek.key.tail.head 
becomes FXComposite and seek.key.tail.tail becomes FXMainWindow. 
cache_pos is not end() and cache_pos->key equals seek.key. However, 
cache_pos->offset equals cache_element::not_found so it returns zero.

FXMainWindow definitely inherits FXComposite. If polymorphic is true, 
it appears to create a dynamic_id via a RTTI lookup. The *only* 
difference is that dynamic_id.second now is a FXMainWindow_Wrapper 
rather than a FXMainWindow. Again it finds an entry identical to 
before except seek.key.tail.tail becomes FXMainWindow_Wrapper. Now 
the differences begin, cache_pos->key is not seek.key so the early 
exit isn't taken. It goes on instead to search the full_graph() 
rather than up_graph() where it finds it, and the correct result is 

Q: What's in cache() precisely? I understand that it's used to 
determine the offsets of base class instance data within a derived 
class. But does it contain every instance of every class within it, 
or just one representative instance?

I only say this because it looks here that because no instance of 
FXMainWindow is ever created by the program, it's not in the cache 
and thus its offset member is cache_element::not_found. If however it 
gets FXMainWindow_Wrapper, that has been created and thus it is 
found. Of course, I am confusing two different search mechanisms for 
static and polymorphic types here.

I should add that my small repeatable example has the wrapper too, 
yet it oddly enough works fine. So it can't be as simple as that.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 208 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20031103/de41cca9/attachment.pgp>

More information about the Cplusplus-sig mailing list