Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!inria!irisa!boissier From: boissier@irisa.fr (franck boissiere) Newsgroups: comp.std.c++ Subject: Re: the most dissatisfying part of c++ Message-ID: <1990Aug2.061225.22629@irisa.fr> Date: 2 Aug 90 06:12:25 GMT References: <56236@microsoft.UUCP> Sender: news@irisa.fr Organization: IRISA, Rennes (FR) Lines: 46 From article <56236@microsoft.UUCP>, by bobatk@microsoft.UUCP (Bob ATKINSON): > > Yes, this is tedious for the class writer, but it makes client's job > a lot easier. I personally agree, though, that it would be > worthwhile investigating making the following constructions legal: > > class Collection { > public: > virtual Collection * Copy(); > }; > > class Set : public Collection { > public: > virtual Set * Copy(); // illegal today > }; > > > At present, this gives an illegal virtual return type error. > > The change to the existing rules is to allow overidings of virtual > functions to return a type to which a standard conversion may be > applied to obtain the inherited return type. ("standard conversion" > may be too general; perhaps only derived-to-base standard conversions > should be applicable). The appropriate member function signature would > be chosen according to the static type of the pointer through which > it is invoked. As you said this is a tedious task for the programmer and I would propose a construct such as: class Collection { public: virtual WHATEVER_CONCSTRUCT_MEANING_THE_CLASS_OF_RECEIVER * Copy(); }; With such an approach you still get type checking and you don't have to rewrite the same line for each class in the subclass hierarchy. You would gain a lot and could then write truly generic behaviors. This would be a good starting point for reusable classes. The same idea could be extended for arguments if needed. -- Franck BOISSIERE boissier@irisa.irisa.fr Prototyping Lab Manager boissier@ccettix.UUCP C.C.E.T.T. B.P. 59 boissier%irisa.irisa.fr@uunet.uu.net 35512 CESSON SEVIGNE CEDEX FRANCE