This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/9377: g++ 64bit calls wrong function -> Multi-inheritance: pointerto member function of the 2nd base calss points to wrong place


Answers to the following questions:
> My questions are (maybe you can send an answer to these):
> - why do you need the cast from &B2::bar to D::*? I
>   think that's the crucial step -- if your program is
>   supposed to work, then this cast would not be necessary,
>   but rather be an implicit default conversion.
> - what's the purpose of the select() method you have there?
>   The comment implies that without it, there's a problem.
>   But what exactly is it?

(1) The "select() method" was put there for another 64-bit
    C++ compiler, not for g++ 64-bit compiler. It does not
    influence 64-bit g++ compiling (I forgot to delete it when
    I was submitting the gnat report). it can be deleted or
    kept there.

(2) The C++ code was reduced from a C++ program written to
    test the pointer to member function and the virtual function
    table. The cast may be useful - it will direct the pointer
    to where the programmer wants, and it may be helpful for
    function returning when multi-inheritance occurs,
    for example, a C++ programmer may write:
/*************************************************************/
// put the classes B1, B2, and D here

typedef char * (D::*PMF)() ;

PMF select(int flag) {
        if (flag==0) return &B1::foo ; //the cast occurs here
        else return &B2::bar ;
}

main() {
        int codition = 1;

        D *d1ptr = new D ;     //another kind of polymorphism?
        printf( "%s\n", (d1ptr->*select(condition)() ) ;

        d1ptr = (D*) new B2 ;  //with the cast, we can also do this
        printf( "%s\n", (d1ptr->*select(1))() ) ;

        return 0 ;
}
/*************************************************************/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]