Topic: Virtual Function Return Types (r.10.2)
Author: davidc@bruce.cs.monash.edu.au (David Chatterton)
Date: 2 Mar 1994 03:37:26 GMT Raw View
Hi,
With the restriction on the return types of virtual functions being relaxed
(r.10.2) so that overriding functions in derived classes may have different
return types, as long as the return type is a derived type of the original
return type (*gasp*), how should a compiler handle this situation:
class X
{
public:
virtual X* f();
};
class Y : public X
{
public:
virtual Y* f();
};
class Z : public Y
{
public:
virtual X* f(); // Is this an error?
};
main()
{
Y* i = new Y;
Y* j = new Z;
Y* k = i.f(); // returns a Y* so this is OK
Y* l = j.f(); // returns a X* - woops
}
Hopefully the declaration in class Z is illegal?
David
David Chatterton | "A new character has come on the scene (I am sure I did
Comp Sci Department, | not invent him, I did not even want him, though I like
Monash Uni, Clayton, | him, but there he came, walking out of the woods of
Australia, 3168. | Ithilien): Faramir, the brother of Boromir."
Phone: 03 905 5375 | - in a letter from JRR Tolkien to his son, 4 May 1944.
email: davidc@bruce.cs.monash.edu.au