Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!netnews.upenn.edu!saul.cis.upenn.edu!limsoon From: limsoon@saul.cis.upenn.edu (Limsoon Wong) Newsgroups: comp.std.c++ Subject: the most dissatisfying part of c++ Message-ID: <27793@netnews.upenn.edu> Date: 6 Aug 90 16:04:49 GMT Sender: news@netnews.upenn.edu Reply-To: limsoon@saul.cis.upenn.edu.UUCP (Limsoon Wong) Organization: University of Pennsylvania Lines: 74 first a message from jeremy grodberg, --------------------------------X---------------------------- Sorry I can't post this, but our posting software is broken. You can post this for me if you like. Why would you want to have a function that returns an a& be allowed to replace a b object *as a default*. It is inherently dangerous, since the function only affects the "a" part of b, which, for operators like + and = is probably not sufficient. The sample code you wrote shows that the function test really should be defined as returning void, so that you would write: B.test(); B = B; -- Jeremy Grodberg jgro@apldbio.com "Beware: free advice is often overpriced!" --------------------------------X---------------------------- my reply: the suggestion is a valid alternative, though the assignment `B = B' is unnecessary. however, that is not what i am getting at. i am mere pointing out what i consider the part of c++ that requires improvement: unnecessary loss of type information. it is clear that before and after performing `B.test()', the object identity of `B' remains invariant. hence, `B' and `B.test()' should be given the same type. but `B.test()' is given type `a', which is much weaker than `b'. it is very annoying to have an object that gets progressively weaker every time you do something to it. more comments on other replies: the template suggestion was a very good try. but it does not work in general. nevertheless, modifications to c++'s type specification along tha line seems to be the most satisfactory solution. i would like a keyword `SUB' to be used as type in class specification in the following way. class C { public: (...SUB...) f(..); A p(..SUB...); }; class D : public C { something }; where `(...SUB...)' is any type expression involving `SUB'. let `d' be a class `D' object. i want d.f be given the type * (..) -> (...D...) d.p be given the type * (..D...) -> A that is, `SUB' is a place holder. it gets replaced by the corresponding subclass. i think it does not complicate type checking or implementation; in particular, its with multiple inheritance. therefore, i do wish something like this be provided. limsoon.