This is the mail archive of the gcc@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]

Re: Covariant returns?


> Date: Mon, 6 Mar 2000 22:46:58 -0500 (EST)
> From: Chris Heath <cheath@umich.edu>

> Worse, in the multiple inheritance case, the compiler doesn't
> produce any error message, but produces incorrect code. Here's an
> example:

No, the problem you're seeing is much worse and harder for us to fix.
That is the correct output from the compiler.  Only your understanding
of C++ is flawed.  Welcome to C++:

#include <stdio.h>
 
struct A {
  virtual A* ThisA() {return this;}
};
 
struct B {
  virtual B* ThisB() {return this;}
};
 
struct C : A, B {
  virtual C* ThisC() {return this;}
};
 
main () {
  C cl;
  C* c=&cl;
  B* b=&cl;
  A* a=&cl;
  printf("%p %p %p\n", c, b, a);
  printf("%p %p %p\n", c->ThisC(), b->ThisB(), a->ThisA());
}

effff748 effff74c effff748
effff748 effff74c effff748

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