This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Covariant returns?
- To: cheath at umich dot edu, gcc at gcc dot gnu dot org
- Subject: Re: Covariant returns?
- From: Mike Stump <mrs at windriver dot com>
- Date: Mon, 6 Mar 2000 20:39:57 -0800 (PST)
> 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