in reply to XS typemap and C++ multiple inheritance

OK, when you cast the D* to a void*, you must recover it by un-doing the exact same cast, and casting it to a D*. That's a general principle in C++.

So, when you do the XS stuff, be consistant about which type of pointer you put into the void, so you get the same thing out. Then, having gotten out your standard form, then dynamic_cast it to the type you really wanted.

—John

  • Comment on Re: XS typemap and C++ multiple inheritance

Replies are listed 'Best First'.
Re: Re: XS typemap and C++ multiple inheritance
by FrenchZ (Initiate) on Aug 06, 2001 at 15:55 UTC
    Thank you John,
    Your analysys is the same than mine. But my problem is how to put into the void* my true type.

    I really don't see how. Except if the void* that I put in my T_X_PTR would be a little encapsualted C Struct like:
    enum MyType {D1_TYPE, B1_TYPE, B2_TYPE, D2_TYPE};
    struct XS_TypeInfo
    {
    void* info;
    enum MyType trueType;
    };

    But even with that means that I would have to rewrite my typemap. and to hard-code in it the decoding of the void* info depending on trueType.

    TIA,
    ~Xavier

      If they are not all related into a single concrete derived class, then yes that's the way to do it. Your question showed an example of multiple inheritance, though, so the fix there is to always be consistant as to what you cast it to before sticking it in the void*.

      —John

        Hi John, My problem with this kind of solution is that all the type and inheritance hierarchy are hard-coded in the typemap.
        So if you add a new derived class or if you modify the inheritance (remove a base class) I will have to modify the typemap. If I miss one modification or do a wrong modif I would end up with really bad stuff.

        Don't you a automatic way of doing it or maybe a more extensible way than the enum Type ?

        TIA again,

        ~Xavier