Covariant returns?

Mike Stump mrs@windriver.com
Mon Mar 6 20:40:00 GMT 2000


> 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


More information about the Gcc mailing list