Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!tektronix!tekecs!nobody From: nobody@tekecs.TEK.COM (-for inetd server command) Newsgroups: comp.lang.c++ Subject: Overloading virtual functions with a different return type Message-ID: <11034@tekecs.TEK.COM> Date: 17 Feb 89 18:38:01 GMT Reply-To: brucec@demiurge.GWD (Bruce Cohen) Organization: Tektronix, Inc., Wilsonville, OR Lines: 44 I'm using cfront 1.2, and I wan to build a set of classes derived from an abstract base class which are a kind of "smart pointer", i.e., they can retrieve the objects they point to from storage somewhere if they are not currently resident in the program's address space. The macro solution to generic container classes is not appealing, and I'm willing to put up with some limitations to avoid it, but one thing disturbs me: I can't have virtual functions which are declared to return an object of the type which the derived class manages, even if it's a subclass of the type managed by the bas class. For instance: class Base { public: virtual void* Obj() { return obj; } protected: void* obj; }; class Derived : public Base { public: virtual int Obj() { return (int)obj; } }; gives me the following message: error: virtual Derived::Obj() type mismatch: int Derived::() and void *Base::() even though void* is in effect an anonymous type, and there is not really a type mismatch. Obviously, I can get this example to compile by making the functions non-virtual, but that removes the nice polymorphism I wanted to begin with. Question 1: is this really a language issue, or just a quirk of the current version of cfront? Question 2: can anyone suggest a way around this? Bruce Cohen Interactive Technologies Division, Tektronix, Inc. M/S 61-028, P.O. Box 1000, Wilsonville, OR 97070 brucec@demiurge.gwd.tek.com, SOON TO BE: brucec@orca.wv.tek.com