C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Address-of-member syntax

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Marcus
Guest





PostPosted: Sat Aug 26, 2006 4:06 am    Post subject: Address-of-member syntax Reply with quote



Out of curiosity... Does anybody know why we use &Class::member instead
of Class::&member? The second form is more consistent with ::*, .* and
->*.

---
[ 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.comeaucomputing.com/csc/faq.html ]
Back to top
Seungbeom Kim
Guest





PostPosted: Sat Aug 26, 2006 9:10 am    Post subject: Re: Address-of-member syntax Reply with quote



Marcus wrote:
Quote:
Out of curiosity... Does anybody know why we use &Class::member instead
of Class::&member? The second form is more consistent with ::*, .* and
->*.

We are taking the address of (Class::member), hence the notation
&Class::member. On the other hand, in the case of class::*pm, obj.*pm
or ptr->*pm, (*pm) specifies the name of a member without specifying the
object (you can mentally replace it with the actual name of the member),
so *pm can be taken as a conceptual unit.

--
Seungbeom Kim

---
[ 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.comeaucomputing.com/csc/faq.html ]
Back to top
Greg Herlihy
Guest





PostPosted: Sun Aug 27, 2006 11:14 pm    Post subject: Re: Address-of-member syntax Reply with quote



Marcus wrote:
Quote:
Out of curiosity... Does anybody know why we use &Class::member instead
of Class::&member?

For one reason, "Class::&member" would conflict with "&member" inside
Class's scope (the latter is an ordinary pointer, and not a member
pointer.) A better question would probably be why Class::&member is not
valid syntax as in, say: this->Class::&member.

Quote:
The second form is more consistent with ::*, .* and
->*.

The syntax for operations involving objects should be distinct from the
syntax for operations involving classes (such as obtaining a member
pointer for a class).

Greg

---
[ 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.comeaucomputing.com/csc/faq.html ]
Back to top
kanze
Guest





PostPosted: Mon Aug 28, 2006 4:21 pm    Post subject: Re: Address-of-member syntax Reply with quote

Greg Herlihy wrote:
Quote:
Marcus wrote:
Out of curiosity... Does anybody know why we use
&Class::member instead of Class::&member?

For one reason, "Class::&member" would conflict with "&member" inside
Class's scope (the latter is an ordinary pointer, and not a member
pointer.)

Can you show a case where something lik Class::&member is
currently anything but a syntax error? I can't think of one.

Quote:
A better question would probably be why Class::&member is not
valid syntax as in, say: this->Class::&member.

What would it mean?

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


---
[ 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.comeaucomputing.com/csc/faq.html ]
Back to top
Greg Herlihy
Guest





PostPosted: Tue Aug 29, 2006 4:13 am    Post subject: Re: Address-of-member syntax Reply with quote

kanze wrote:
Quote:
Greg Herlihy wrote:
Marcus wrote:
Out of curiosity... Does anybody know why we use
&Class::member instead of Class::&member?

For one reason, "Class::&member" would conflict with "&member" inside
Class's scope (the latter is an ordinary pointer, and not a member
pointer.)

Can you show a case where something lik Class::&member is
currently anything but a syntax error? I can't think of one.

Class::&member is currently a syntax error. But the point is that if it
were defined, it should be defined as a qualified version of "&member"
instead of as "&Class::member" is defined today. Otherwise, within the
Class class, the meaning of the two expressions "&member" and
"Class::&member" would differ.

Quote:
A better question would probably be why Class::&member is not
valid syntax as in, say: this->Class::&member.

What would it mean?

The same as &member does today, only with added qualification.
Currently, a program must use &(Class::member) or &this->Class::member
when qualification is needed. For example:

struct A
{
int member;
};

struct B
{
int member;
};

struct C : public A, public B
{
int * GetIntPtr()
{
/*
return &member; // error: 'member' ambiguous
return B::&member; // error: invalid syntax
return &B::member; // error: type mismatch
*/

return &(B::member); // OK
return &this->B::member; // OK
}
};

---
[ 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.comeaucomputing.com/csc/faq.html ]
Back to top
kanze
Guest





PostPosted: Tue Aug 29, 2006 4:41 pm    Post subject: Re: Address-of-member syntax Reply with quote

Greg Herlihy wrote:
Quote:
kanze wrote:
Greg Herlihy wrote:
Marcus wrote:
Out of curiosity... Does anybody know why we use
&Class::member instead of Class::&member?

For one reason, "Class::&member" would conflict with
"&member" inside Class's scope (the latter is an ordinary
pointer, and not a member pointer.)

Can you show a case where something lik Class::&member is
currently anything but a syntax error? I can't think of
one.

Class::&member is currently a syntax error. But the point is
that if it were defined, it should be defined as a qualified
version of "&member" instead of as "&Class::member" is defined
today.

What's a "qualified version of &member"? Currently, names are
qualified, not what they name. If I write member, without
qualification, I get whatever symbol member refers to, according
to unqualified name lookup. If I write Class::member, name
lookup takes place only in that class.

Quote:
Otherwise, within the Class class, the meaning of the two
expressions "&member" and "Class::&member" would differ.

Yes, but why should the second be legal to begin with?

Quote:
A better question would probably be why Class::&member is
not valid syntax as in, say: this->Class::&member.

What would it mean?

The same as &member does today, only with added qualification.

Qualification of what? Names are qualified, not expressions. I
can write C::a + b, with the name of a qualified, but it makes
no sense to write C:Sada + b), because the results of an
expression is a value, not a symbol. Qualification affects name
lookup, and not values. (There are a few exceptions. In a
function call, if the name of the function is a qualified name,
then dynamic dispatch is not used. Which seems a bit arbitrary,
when you think of it---there is no way to inhibit dynamic
dispatch when calling through a pointer to member function, for
example.)

Quote:
Currently, a program must use &(Class::member) or
&this->Class::member when qualification is needed.

Which is normal: you put the qualifier in front of what is being
qualified.

Quote:
For example:

struct A
{
int member;
};

struct B
{
int member;
};

struct C : public A, public B
{
int * GetIntPtr()
{
/*
return &member; // error: 'member' ambiguous
return B::&member; // error: invalid syntax
return &B::member; // error: type mismatch
*/
return &(B::member); // OK
return &this->B::member; // OK
}
};

Which all seems perfectly natural once you understand what
qualification is. Why do you want to apply it to expressions?
(And presumably only to some expressions---I doubt that you want
A:Sada + b). So why some expressions, and not others?)

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


---
[ 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.comeaucomputing.com/csc/faq.html ]
Back to top
Yuu
Guest





PostPosted: Tue Aug 29, 2006 4:59 pm    Post subject: Re: Address-of-member syntax Reply with quote

Greg:
Quote:
Class::&member is currently a syntax error. But the point is that if it
were defined, it should be defined as a qualified version of "&member"

A qualified version of &member would be &Class::member (::& would be
understood as a single operator).

Currently, a qualified version of &member is expressed as a very
confusing &(Class::member) or &this->Class::member, as you explain in
your message (quoted below). By using ::&, the meaning of
&Class::member and &(Class::member) could be the same, as one would
expect. Too bad this is not how the language evolved...

Quote:
Currently, a program must use &(Class::member) or &this->Class::member
when qualification is needed. For example:

struct A
{
int member;
};

struct B
{
int member;
};

struct C : public A, public B
{
int * GetIntPtr()
{
/*
return &member; // error: 'member' ambiguous
return B::&member; // error: invalid syntax
return &B::member; // error: type mismatch
*/

return &(B::member); // OK
return &this->B::member; // OK
}
};

---
[ 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.comeaucomputing.com/csc/faq.html ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.