This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
covariant returns and multiple inheritance.
- To: <gcc at gcc dot gnu dot org>
- Subject: covariant returns and multiple inheritance.
- From: "Alexander Rozenman" <shure at sd dot co dot il>
- Date: Mon, 30 Jul 2001 10:39:03 +0300
Hello gcc team !
I wrote very simple test case for covariant return types in C++.
The compilation with gcc 3.0 (sparc-solaris) was successful,
but when I run my a.out I get very strange result - the pointers
'b' and 'b->getThis()' are different.
// ----------------------------------------------------------
#include <iostream.h>
class A {
public:
virtual A* getThis() { return this; }
};
class B {
int a;
public:
virtual B* getThis() { return this; }
};
class AB : public A, public B {
public:
virtual AB* getThis() { return this; }
};
int main () {
using namespace std;
AB* ab = new AB();
A* a = ab;
B* b = ab;
cout << a << " " << a->getThis() << endl;
cout << b << " " << b->getThis() << endl;
return 0;
}
// ----------------------------------------------------------
P.S. I checked the testcase with gcc.2.95.2,
but result the same. Some other compilers
(HP's aCC and Microsoft's CL.exe) reports
"Not implemented" error.
I guess that this is a complicated issue ...
best regards,
Alex.