"David Hilsee" <> wrote in message
news:25KdnR1CoaexbKHcRVn-...
> "JKop" <> wrote in message
> news:Ss5%c.26732$...
> > You can overload the address-of operator. Consider a simple class:
> >
> > class Blah
> > {
> > public:
> >
> > Blah* operator&()
> > {
> > return this;
> > }
> > };
> >
> > Now... consider if "this" was a reference (as before I've argued it
should
> > be):
> >
> > class Blah
> > {
> > public:
> >
> > Blah* operator&()
> > {
> > return &this;
> > }
> > };
> >
> >
> > looks like an infinite loop to me...
> >
> >
> > Although to be honest I would've prefered "p_this".
>
> In "The Design and Evolution of C++", Bjarne Stroustrup says that "this"
is
> a pointer and not a reference because references were not present in "C
with
> Classes" at the time that "this" was introduced.
I did a quick search and found that many people already said this the first
time you brought this up. I must have missed the discussion the first time
around. I'll add something new by pointing out that your overload of
operator& has little bearing on the matter, because it is rarely (if ever)
used in the way that you are using it. Normally, operator& is overloaded to
_alter_ the return value. If you just want to return "this", then you don't
need to overload operator&.
If you really wanted the address and wanted to avoid invoking operator&, you
could use something like boost's addressof
(
http://www.boost.org/libs/utility/ut...htm#addressof), so it wouldn't
matter if "this" was a reference.
--
David Hilsee