This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/9377: g++ 64bit calls wrong function -> Multi-inheritance: pointerto member function of the 2nd base calss points to wrong place
- From: axiong at ca dot ibm dot com
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 21 Jan 2003 20:56:01 -0000
- Subject: Re: c++/9377: g++ 64bit calls wrong function -> Multi-inheritance: pointerto member function of the 2nd base calss points to wrong place
- Reply-to: axiong at ca dot ibm dot com
The following reply was made to PR c++/9377; it has been noted by GNATS.
From: axiong@ca.ibm.com
To: bangerth@dealii.org, "Andrew Xiong" <axiong@ca.ibm.com>,
gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org,
gcc-gnats@gcc.gnu.org
Cc:
Subject: Re: c++/9377: g++ 64bit calls wrong function -> Multi-inheritance: pointer
to member function of the 2nd base calss points to wrong place
Date: Tue, 21 Jan 2003 15:49:59 -0500
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 ;
}
/*************************************************************/