Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!att!westmark!mole-end!mat From: mat@mole-end.UUCP (Mark A Terribile) Newsgroups: comp.lang.c++ Subject: Re: Why use reference type over pointer type? Summary: Is there an FAQ list Message-ID: <422@mole-end.UUCP> Date: 6 Aug 90 05:24:49 GMT References: <1676@dinl.mmc.UUCP> <1806@cs.rit.edu> Organization: mole-end--private system. admin: mole-end!newtnews Lines: 37 > > Its obvious, I'm new to C++. > > What does does a reference type give me over a pointer type > > that I've come to love and know well in C? ...... This sound like a candidate for an FAQ (frequently asked questions) list. > I, as a professor, have been asked this so many times that I would love > to hear people's opinions on this. > > I personally prefer to use them because I like > > call-by-reference semantics > "lvalue" - type variables > > but I do not care for aliases. > > I do have a hard time justifying their existence to more practically-minded > students, however. Well, for one thing, by changing just the declaration for the CALLED function, you control (with appropriate typechecking) whether you have call by copy- value or call-by-reference. This is definitely a maintanance win that ought to interest practically-minded students. For another, the type system considers X& to be the same as X for the purpose of overloading resolution and conversions. This means that the same rules apply whether call-by-reference or call-by-value is involved. There are good reasons to not allow overloads of operator+( X* , X* ) , not the least of which is that the code using this operator would have to be written in a strange way and that no member form would be possible; these problems don't affect operator+( X&, X& ) . -- (This man's opinions are his own.) From mole-end Mark Terribile