From 449777950889588554
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,6d5520f8ce526ad5,start
X-Google-Attributes: gidf78e5,public
From: Jim Cobban <thesnaguy@hotmail.com>
Subject: Pointer to member function restriction in standard
Date: 2000/01/24
Message-ID: <388CC286.B7848872@hotmail.com>#1/1
X-Deja-AN: 577116269
X-NNTP-Posting-Host: 206.191.1.177
Approved: stephen.clamage@sun.com (comp.std.c++)
X-Accept-Language: en
X-UID: 0000000001
X-Status: $$$T
Content-Type: multipart/mixed; boundary="------------2A153B3BFFFFB9C79A044A80"
Organization: Magma Communications Ltd.
Mime-Version: 1.0
NNTP-Posting-Date: Mon, 24 Jan 2000 16:19:55 EDT
Newsgroups: comp.std.c++
Originator: clamage@taumet


This is a multi-part message in MIME format.
--------------2A153B3BFFFFB9C79A044A80
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Could someone please explain to me the rationale behind the restriction
documented in paragraph 3 of section 5.3.1 of the standard:

"A pointer to member is only formed when an explicit & is used and its
operand is a qualified-id not enclosed in parentheses. [Note: that is,
the expression &(qualified-id), where the qualified-id is enclosed in
parentheses, does not form an expression of type <pointer to member>
Neither does qualified-id, because there is no implicit conversion from
a qualified-id for a nonstatic member function to the type <pointer to
member function> as there is from an lvalue of function type to the type

<pointer to function> (4.3). Nor is &unqualified-id a pointer to member,

even within the scope of the unqualified-id's class. ]"

The result of this restriction is what seems unnecessarily ugly code in
my program.

I am writing a state based parser. So at the end of processing each
token I want to set the state for handling the next token.  At first I
did this with an enumeration, but that then required a switch statement
to select the function to be called for each state, so I decided to use
a pointer-to-member-function.  But that requires the ugly syntax:

 pmf = &ClassName::StateFunc;

where, as the standard says this qualification would not be required if
I were not writing this code using classes.  I therefore feel that the
standard is, in this situation, penalizing me for wanting to program
using
object oriented techniques.

Note that the enforcement of this restriction varies by compiler.  I
have tried it on Borland, which issues an error message, and on
Metrowerks, which accepts the short-hand pmf = StateFunc;

--
Jim Cobban   jcobban@magma.ca
34 Palomino Dr.
Kanata, ON, CANADA
K2M 1M1
+1-613-592-9438


--------------2A153B3BFFFFB9C79A044A80
Content-Type: text/x-vcard; charset=us-ascii;
 name="thesnaguy.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Jim Cobban
Content-Disposition: attachment;
 filename="thesnaguy.vcf"

begin:vcard 
n:Cobban;James
tel;fax:+1-613-592-9438
tel;home:+1-613-592-9438
x-mozilla-html:FALSE
url:http://www.magma.ca/~jcobban
version:2.1
email;internet:thesnaguy@hotmail.com
title:Consultant
adr;quoted-printable:;;34 Palomino Dr.=0D=0A;Kanata;ON;K2M 1M1;Canada
fn:Jim Cobban
end:vcard

--------------2A153B3BFFFFB9C79A044A80--



[ 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              ]




