Covariant returns?
sidster
patrick@mail.boxsoft.com
Tue Mar 7 00:45:00 GMT 2000
* Martin v. Loewis (martin@loewis.home.cs.tu-berlin.de) [20000307 00:28]:
> > 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.
>
> It seems my understanding of C++ is flawed, too. Can you elaborate why
> the compiler is acting correctly for his example? I'd assume it is a
> bug in the compiler to return a C* from a method that statically
> returns a B*.
The This() methods were specified to be virtual. Meaning if you have a
pointer of a base type to the dereived object and you invoke any virtual
methods that are defined in the derived class the actual method invoked
will be the one for the derived class.
That is why invoking a->This(), b->This(), c->This()
will all invoke C::This()
Regards,
patrick
--
It's a damn poor mind that can only think of one way to spell a word.
-- Andrew Jackson
More information about the Gcc
mailing list