Topic: I guess I've got it - or have I?
Author: AllanW <allan_w@my-deja.com>
Date: 1999/06/04 Raw View
In article <7iemn5$5hb$1@nnrp1.deja.com>,
Andrei Alexandrescu <andrewalex@hotmail.com> wrote:
> Hi,
Hi!
> I think I understood why there are not references to member functions.
> void (A::& rF)() = A::f;
> A a;
> a.rF();
> The operator .* or ->* would not be needed anymore, because a
> reference acts just as the object it refers to.
> This would have complicated things a lot, because of naming
> ambiguities
> (what if rF above would have been the name of another method of A? It
> would basically allow one to mask member functions, or it would have
> introduced additional, strange rules.)
I suppose this could have been solved with another operator.
Use .* or ->* for a pointer-to-member-function, and use .&
or ->& for a reference-to-member-function.
(I'm not proposing this, but it makes sense.)
> This makes references to functions look worse, because they were
> introduced for completion, but now references aren't complete anyway.
>
> Is this the real reason? Thanks.
I can't say for sure (not a committee member), but it doesn't
seem likely to me. Following the logic in D&E we can say that
it doesn't add anything to the language because it makes the
language bigger (do we really need another operator?) and
because the identical functionality is already available
elsewhere (via pointer to member).
Note that references were an absolute language neccesity, not
a 'mere' notational convenience. (Try to imagine how a copy
constructor would look if we didn't have references in the
language.) The same cannot be said about references to members.
--
Allan_W@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in newsgroups only, sorry.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Andrei Alexandrescu <andrewalex@hotmail.com>
Date: 1999/05/25 Raw View
Hi,
I think I understood why there are not references to member functions.
Previously I thought this is an incompleteness of the type system - you
can have references to almost everythig, except member functions.
To be consistent, references to member functions would be used like
this:
struct A
{
void f();
};
int main()
{
void (A::& rF)() = A::f;
A a;
a.rF();
}
The operator .* or ->* would not be needed anymore, because a reference
acts just as the object it refers to.
This would have complicated things a lot, because of naming ambiguities
(what if rF above would have been the name of another method of A? It
would basically allow one to mask member functions, or it would have
introduced additional, strange rules.)
This makes references to functions look worse, because they were
introduced for completion, but now references aren't complete anyway.
Is this the real reason? Thanks.
Andrei
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]