Re: More keyword abomination by C++0x
On Apr 28, 8:53 pm, "Chris Morley" <chris.mor...@lineone.net> wrote:
"Nevin :-] Liber" <ne...@eviloverlord.com> wrote in messagenews:nevin-7C5A09.17343327042009@chi.news.speakeasy.net...
If you didn't have references, what would you return from operator=(),
operator++(), etc.?
Could have been done with pointers, but wasn't so doesn't really matter ;)
mytype* operator=(const mytype* Rhs) { ...; return this;}
Would have worked equally as well.
No, it wouldn't. If you defined this operator, then how would you
assign one pointer to another?
Or rather, how do you explain to a newcomer to the language that
mytype* operator=(const mytype* rhs);
is not used when doing this:
mytype *p = new mytype;
There is just so much duplication across pointers & references in my
opinion. References make for neater reading code:
int foo(int& a, int& b) {return a-b;} vs. int foo(int* a, int* b) {return
*a-*b;} & . instead of ->
But anytime you want 'object or NULL' behaviour I use pointers anyway.
Obviously. The fact that references can't be null is a great help in
most situations. For those where it isn't, you can of course use
pointers. But I prefer Boost.Optional.
Sebastian
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]