TITLE: Manual simulation of covariant return types [ This is one response to a long discussion of the merits of using an idiom which involves the use of private virtual methods. More discussion of this will appear in future tips. By the way, I reformatted the code example below. -adc ] PROBLEM: doug@monet.ads.com (Doug Morgan) Another nice thing about public nonvirtuals inline calling private virtuals is that you needn't wait for your favorite compiler vendors to all implement covariant type returns for virtual functions. You can "do it yourself" on the nonvirtual functions (e.g., by using down casts inside the public inline nonvirtual members that call the private virtual members). You can even implement covariant returns of actual objects, not just pointers and references (as John has pointed out is a safe thing to do, but not allowed in the current ANSI thinking about virtual members). You will likely have to create a private virtual function of a brand new name (to prevent slicing) and redefine the old private virtual too, but that may not be too bad. RESPONSE: maxtal@physics.su.OZ.AU (John Max Skaller), 31 May 94 Wow. I've actually been building models of inheritance, it never occurred to me to use the technique in real programs! Hm. This is worth trying, if only to prove it can be implemented easily. class A {}; class B : public A {}; class X { virtual A f(); public: A F() { return f(); } }; class Y : public X { virtual B g(); // covariant virtual A f() { return g(); } public: B F() { return g(); } }; I see. The covariant return is only useful when called with the right static type. Its just overloading. But the call through the base X is still polymorphic. Nice. Thanks! This makes me wonder why the committee did not choose to support covariant value returns. Is there something wrong with the above technique implemented by a compiler automatically?