Hi,

I'm using "gcc version 3.4.3 (Mandrakelinux 10.2 3.4.3-7mdk)". (but same thing occurs on a older version).

I fall into an "invalid covariant return type" during a project development. I didn't manage to reproduce this error, in a short example... But, while trying, I fall into a very strange behavior. I find an example which worked or failed at compil time depanding on the way the class inherit together (it works when public and fails when private) !!

So, this is working

  class A {};

  class B
  {
     virtual A* getA();
  };

  class D_A : public A {};

  class D_B : public B
  {
    virtual D_A* getA();
  };

and, this is not working:

  class A {};

  class B
  {
     virtual A* getA();
  };

  class D_A :  A {};

  class D_B :  B
  {
    virtual D_A* getA();
  };

and is producing:
test2.cc:23: error: invalid covariant return type for `virtual D_A* D_B::getA()'test2.cc:9: error: overriding `virtual A* B::getA()'

Very strange, isn't it ?

Cheers,
T.

Reply via email to