Hi all,

I have some object with multiple inheritance :

class D : public B1, public B2

I made XS interface for B1,B2 and D classes, and I set ISA to match inheritance in the perl packages.

I have a function that have parameters from type B2 and I want to pass a D to this function.

int func(B2* obj1,B2* obj2){ return obj1 == obj2; } D* d_ptr = new D();<BR> B2* b2_ptr = dynamic_cast<B2*>(d_ptr);<BR> func(d_ptr,b2_ptr); --> return true

this works fine in full C++ but in the XS mapping the following process is in action: D* object is cast on a void* to be came a perl reference. then this void * is cast into a B2*.

here is my perlobject.map:

# "perlobject.map" Dean Roehrich, version 19960302<BR> #<BR> # TYPEMAPs<BR> #<BR> ############################################################<BR> OUTPUT<BR> # The Perl object is blessed into 'CLASS', which should be a<BR> # char* having the name of the package for the blessing.<BR> T_X_PTR<BR> sv_setref_pv( $arg,${ntype}_Package, (void*)$var );<BR> <p> ############################################################<BR> INPUT<BR> T_X_PTR<BR> if(sv_derived_from($arg,${ntype}_Package)) { <BR> IV tmp_ = SvIV((SV*)SvRV($arg));<BR> $var = ($type)tmp_;<BR> }<BR> else<BR> croak(\"$var is not of type %s\",${ntype}_Package);<BR>

if I compare the final B2* and the original D*, the address of the pointed object has changed due to the void* cast that do not work correctly with multiple inheritance.
This is a problem for me because I compare addresses of objects. so that the function return false!!

Do you know how to fix this?
Is there a safe way to map multiple inherited objects in perl ??

thanks in advance

Edit kudra, 2001-08-08 Added code tags


In reply to XS typemap and C++ multiple inheritance by FrenchZ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.