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]

covariant returns and multiple inheritance.


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.



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