Topic: conversion to function pointers (class member functions)
Author: AllanW@my-dejanews.com
Date: 1999/02/17 Raw View
In article <36C9B136.33137EB9@technologist.com>,
David R Tribble <dtribble@technologist.com> wrote:
> Biju Thomas wrote:
> >
> > stephen.clamage@sun.com (Steve Clamage) wrote:
> > >
> > > >Are class member function names (e.g. C::f in the example below)
> > > >supposed to be convertible to a pointer to the member function?
> > >
> > > The "&" is required, unlike the rule for non-member functions.
> > >
> > > Some compilers accept C::f as meaning &C::f, but that is a
> > > non-standard extension.
> >
> > Since some compilers support it as an extension, it means that it can
> > be done. Then why not make it a standard? At least, for the sake of
> > symmetry with non-member functions. (The same cannnot be done for
> > member data, but, for member functions, I cannot think of any problem
> > it will create.)
>
> Just because it can be done doesn't mean it should be done. IMHO,
> an explicit '&' makes the intention of the code more obvious. And
> it's only a single extra character, after all. Perhaps there are
> bigger issues when dealing with member function pointers, especially
> when used in combination with templates?
When this issue came up last year, someone posted some legal code which
had a different meaning under this rule. Made a believer out of me.
Unfortunately I can't remember what it did and I don't have time to look
it up...
Perhaps whoever posted it then would be so kind as to post it again.
----
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ 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: David R Tribble <dtribble@technologist.com>
Date: 1999/02/16 Raw View
Biju Thomas wrote:
>
> stephen.clamage@sun.com (Steve Clamage) wrote:
> >
> > >Are class member function names (e.g. C::f in the example below)
> > >supposed to be convertible to a pointer to the member function?
> >
> > The "&" is required, unlike the rule for non-member functions.
> >
> > Some compilers accept C::f as meaning &C::f, but that is a
> > non-standard extension.
>
> Since some compilers support it as an extension, it means that it can
> be done. Then why not make it a standard? At least, for the sake of
> symmetry with non-member functions. (The same cannnot be done for
> member data, but, for member functions, I cannot think of any problem
> it will create.)
Just because it can be done doesn't mean it should be done. IMHO,
an explicit '&' makes the intention of the code more obvious. And
it's only a single extra character, after all. Perhaps there are
bigger issues when dealing with member function pointers, especially
when used in combination with templates?
-- David R. Tribble, dtribble@technologist.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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Bill Wade" <bill.wade@stoner.com>
Date: 1999/02/11 Raw View
Dan Yergeau wrote in message <79srme$s0f@antonios.Stanford.EDU>...
> [a.baz wants a pointer to member argument]
> a.baz(C::f); // g++ 2.8.1 and egcs-1.1.1 reject this
> // g++ 2.7.2.x and CC from Sun SC4.2 accept it
This should be rejected.
5.3.1(3) "A pointer to member is only formed when an explicit & is used ..."
---
[ 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: Biju Thomas <bijuthom@ibm.net>
Date: 1999/02/12 Raw View
In article <79tdhd$o0v$1@engnews1.eng.sun.com>,
stephen.clamage@sun.com (Steve Clamage) wrote:
>
> >Are class member function names (e.g. C::f in the example below)
> >supposed to be convertible to a pointer to the member function?
>
> The "&" is required, unlike the rule for non-member functions.
>
> Some compilers accept C::f as meaning &C::f, but that is a
> non-standard extension.
Since some compilers support it as an extension, it means that it can
be done. Then why not make it a standard? At least, for the sake of
symmetry with non-member functions. (The same cannnot be done for member
data, but, for member functions, I cannot think of any problem it
will create.)
Regards,
Biju Thomas
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
[ 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: yergeau@antonios.Stanford.EDU (Dan Yergeau)
Date: 1999/02/10 Raw View
Are class member function names (e.g. C::f in the example below)
supposed to be convertible to a pointer to the member function?
I'm trying to figure out if the error below is a bug in g++ or an
actual error in the program (i.e. "&" is required class member
functions).
Thanks in advance,
Dan Yergeau
yergeau@leland.stanford.edu
============================================================================
class C
{
public:
void f(void);
};
typedef void (*funcPtr)(void);
typedef void (C::* memberFuncPtr)(void);
class A
{
public:
void bar(funcPtr fp);
void baz(memberFuncPtr fp);
};
void foo()
{
A a;
a.bar(foo);
a.bar(&foo);
a.baz(&C::f);
a.baz(C::f); // g++ 2.8.1 and egcs-1.1.1 reject this
// g++ 2.7.2.x and CC from Sun SC4.2 accept it
}
//t2.cc: In function `void foo()':
//t2.cc:23: no matching function for call to `A::baz (void (C::)())'
//t2.cc:14: candidates are: A::baz(void (C::*)())
============================================================================
---
[ 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: stephen.clamage@sun.com (Steve Clamage)
Date: 1999/02/11 Raw View
yergeau@antonios.Stanford.EDU (Dan Yergeau) writes:
>Are class member function names (e.g. C::f in the example below)
>supposed to be convertible to a pointer to the member function?
>I'm trying to figure out if the error below is a bug in g++ or an
>actual error in the program (i.e. "&" is required class member
>functions).
The "&" is required, unlike the rule for non-member functions.
Some compilers accept C::f as meaning &C::f, but that is a
non-standard extension.
--
Steve Clamage, stephen.clamage@sun.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://reality.sgi.com/austern_mti/std-c++/faq.html ]