Topic: references-to-functions


Author: "David Abrahams" <david.abrahams@rcn.com>
Date: Mon, 3 Dec 2001 18:11:21 GMT
Raw View
I recently discovered references to functions. Synopsis:

  int f(char*);
  int (&rf)(char*) = f;

Well, it's not surprising that I hadn't noticed these before. Since you can
also write:

  int (*pf)(char*) = f;

(leaving the address-of operator off of f), there's really not much point in
using a reference-to-function. But then, pointers-to-member-functions don't
work the same way:

  struct X { int f(char*); };
  int (X::*pmf)(char*) = X::f; // error!

you have to write:

  int (X::*pmf)(char*) = &X::f; // ok

Even more strangely, there's no such thing as a
reference-to-member-function:

  int (X::&)(char*) = X::f;
          ^---------syntax error!

Can anyone supply a rationale for these odd asymmetries? D&E is silent on
the topic.

Thanks,
Dave
--
===================================================
  David Abrahams, C++ library designer for hire
 resume: http://users.rcn.com/abrahams/resume.html

        C++ Booster (http://www.boost.org)
          email: david.abrahams@rcn.com
===================================================



---
[ 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://www.research.att.com/~austern/csc/faq.html                ]