Topic: Unary operator & question


Author: b91926@fsgi02.fnal.gov (David Sachs)
Date: 1996/07/17
Raw View
mpr@absoft.com (Michael Rice) writes:

>Section 5.3.1 paragraph 3 of the May 1996 draft [expr.unary.op] states:

>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."

>For example:

>struct A { int a; };

>void m()
>{
>  int A::*mp = &A::a; // fine
>  int A::*np = &(A::a); // an error?
>
>  &(A::a);  // error?
>}

>What is the rationale for requiring that there be no parentheses?
>There obviously was a reason for this, or it wouldn't be spelled out
>in such a way.  Most compilers that I've tried (old, non-standard of
>course) accept either of these and apparently treat them equivalently.

>Also, it states that &(qualified-id) does not form an expression of
>type "pointer to member."  What type of expression does it form?
>Or is it ill-formed?

The requirement that parentheses not be used was done to remove an
ambiguity in the language:

Suppose a class B has a base class A, and both classes have a member
with the same name a. Then in a member function of B the expression
&A::a would have two possible meanings.  The resolution for this was
the &A::a (without parentheses) is always a pointer to member, while
&(A::a) would mean &this->A::a, the address of the a of the A subobject.

--
** The Klingons' favorite food was named by the first earthling to see it **
David Sachs - Fermilab, MSSG MS369 - P. O. Box 500 - Batavia, IL 60510
Voice: 1 708 840 3942      Deparment Fax: 1 708 840 3785
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: mpr@absoft.com (Michael Rice)
Date: 1996/07/17
Raw View
Section 5.3.1 paragraph 3 of the May 1996 draft [expr.unary.op] states:

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."

For example:

struct A { int a; };

void m()
{
  int A::*mp = &A::a; // fine
  int A::*np = &(A::a); // an error?

  &(A::a);  // error?
}

What is the rationale for requiring that there be no parentheses?
There obviously was a reason for this, or it wouldn't be spelled out
in such a way.  Most compilers that I've tried (old, non-standard of
course) accept either of these and apparently treat them equivalently.

Also, it states that &(qualified-id) does not form an expression of
type "pointer to member."  What type of expression does it form?
Or is it ill-formed?


--
Mike Rice (mpr@absoft.com)
Absoft Corporation
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]