Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

... so why do I have to give the class name when getting the address of a member function?

0 views
Skip to first unread message

Andy Champ

unread,
Sep 30, 2009, 4:17:37 PM9/30/09
to
So to steal a couple of lines from the FAQ, I have

typedef int (Fred::*FredMemFn)(char x, float y);
FredMemFn a[] = { &Fred::f, &Fred::g, &Fred::h, &Fred::i };

If this is inside another member function of Fred, why do I have to give
the class name? After all, if I wanted to _call_ f(char, float) it
would happily work it out.

Just curious... (had to code up some calls passing member functions
today, which is not something I do a lot)

Andy

Victor Bazarov

unread,
Sep 30, 2009, 4:51:54 PM9/30/09
to

The boilerplate answer is, "Because the Standard says so in
[expr.unary.op]/2." Not often is it satisfactory, however...

I think that's just how the name lookup works. So, your question is
really, "why does name lookup for pointers-to-member requires the fully
qualified name (member name with name of the class and colons)?" My
guess is to limit the looked-up scope, and thus probably simplify the
process. But I don't know squat about writing that part of the compiler.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

James Kanze

unread,
Oct 1, 2009, 4:31:14 AM10/1/09
to
On Sep 30, 9:51 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> Andy Champ wrote:
> > So to steal a couple of lines from the FAQ, I have

> > typedef int (Fred::*FredMemFn)(char x, float y);
> > FredMemFn a[] = { &Fred::f, &Fred::g, &Fred::h, &Fred::i };

> > If this is inside another member function of Fred, why do I
> > have to give the class name? After all, if I wanted to
> > _call_ f(char, float) it would happily work it out.

> > Just curious... (had to code up some calls passing member
> > functions today, which is not something I do a lot)

> The boilerplate answer is, "Because the Standard says so in
> [expr.unary.op]/2." Not often is it satisfactory, however...

> I think that's just how the name lookup works. So, your
> question is really, "why does name lookup for
> pointers-to-member requires the fully qualified name (member
> name with name of the class and colons)?" My guess is to
> limit the looked-up scope, and thus probably simplify the
> process. But I don't know squat about writing that part of
> the compiler.

I think it's mainly to be coherent with how things work with
data members. If x is an int member of Fred, &x returns an int*
pointing to the x in this object, &Fred::x returns a pointer to
member, which can be used with any object of Fred type (but
requires you to specify the object).

--
James Kanze

Marcel Müller

unread,
Oct 1, 2009, 8:14:48 AM10/1/09
to
Hi,

James Kanze wrote:
> I think it's mainly to be coherent with how things work with
> data members. If x is an int member of Fred, &x returns an int*
> pointing to the x in this object, &Fred::x returns a pointer to
> member, which can be used with any object of Fred type (but
> requires you to specify the object).

I never have seen the latter. An in fact I didn't know that it is possible.
Besides I never missed it. So what is the real world use of it?


Marcel

Victor Bazarov

unread,
Oct 1, 2009, 9:57:23 AM10/1/09
to

Essentially the same as with pointers to member functions. What do you
do with functions? You call them. What do you do with data members?
You use them in expressions. Why do you need pointers to member
functions? So you can make the choice of which function to call
dynamic, based on some run-time condition. Why do you need pointers to
data members? So you can make the choice which object to use in some
expression dynamic, based on some run-time condition. Same thing.

Andy Champ

unread,
Oct 1, 2009, 4:35:11 PM10/1/09
to
James Kanze wrote:
>
> I think it's mainly to be coherent with how things work with
> data members. If x is an int member of Fred, &x returns an int*
> pointing to the x in this object, &Fred::x returns a pointer to
> member, which can be used with any object of Fred type (but
> requires you to specify the object).

Ah, that makes sense. Thanks. And I feel better about asking a
question that has "I think" from both you and Victor!

>
> --
> James Kanze

BTW If that's a signature in the RFC3676 sense you ought to have a space
after the two hyphens.

Andy

--
Like that

Francesco S. Carta

unread,
Oct 1, 2009, 5:21:19 PM10/1/09
to
On 1 Ott, 22:35, Andy Champ <no....@nospam.invalid> wrote:
> James Kanze wrote:

[snip]

> > --
> > James Kanze
>
> BTW If that's a signature in the RFC3676 sense you ought to have a space
> after the two hyphens.
>
> Andy
>
> --
> Like that

I suppose you're using GoogleGroups just like me. Notice the above:
your sig start token is just equal to James' one: it's GG that's
stripping trailing whitespace.

Just out of curiosity, can someone confirm whether this very message,
posted from GoogleGroups with a "-- " sig start below, actually
arrives to other servers _with_ the trailing whitespace?

--
Francesco S. Carta, hobbyist
http://fscode.altervista.org

Bo Persson

unread,
Oct 1, 2009, 5:28:13 PM10/1/09
to

It does, "proven" by the fact that your signature is removed in this
reply.


I'm using the news.individual.net NNTP server.


Bo Persson


Victor Bazarov

unread,
Oct 1, 2009, 5:40:02 PM10/1/09
to

Nope, no confirmation. On my server Andy's message does have a proper
signature, and yours does not. In your reply the "Like that" in the
quoted text also follows an improper (two-dashes-only) signature separator.

I do NOT believe that newsserver software does anything to the message
contents. NewsREADER software does, undoubtedly.

Speakin'a newsreaders, Bo, are you sure your newsreader doesn't remove
any text after two dashes regardless whether there is a space after
them? Let's try this:

--
If this is removed by your newsreader, it's too forgiving (or sings to
Google's tunes).

Alf P. Steinbach

unread,
Oct 1, 2009, 5:43:46 PM10/1/09
to
* Bo Persson:

I think the significant fact is that you're using Microsoft Outlook Express. ;-)

Consider installing OE QuoteFix, if you haven't.


Cheers,

- Alf

James Kanze

unread,
Oct 2, 2009, 3:49:02 AM10/2/09
to
On Oct 1, 9:35 pm, Andy Champ <no....@nospam.invalid> wrote:
> James Kanze wrote:

> BTW If that's a signature in the RFC3676 sense you ought to
> have a space after the two hyphens.

It does have a space after the two hyphens when it leaves here.
I'm posting through Google news, however, so strange things
happen after. (Actually, because of the volatility in my
current situation, I'm entering the signatures by hand, so it's
possible that I do forget the space now and then. In the past,
whether Google ate the space or not seemed to depend on where I
posted from.)

--
James Kanze

James Kanze

unread,
Oct 2, 2009, 3:55:27 AM10/2/09
to
On Oct 1, 10:40 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> Francesco S. Carta wrote:
> > On 1 Ott, 22:35, Andy Champ <no....@nospam.invalid> wrote:
> >> James Kanze wrote:

> > [snip]


> > I suppose you're using GoogleGroups just like me. Notice the
> > above: your sig start token is just equal to James' one:
> > it's GG that's stripping trailing whitespace.

> > Just out of curiosity, can someone confirm whether this very
> > message, posted from GoogleGroups with a "-- " sig start
> > below, actually arrives to other servers _with_ the trailing
> > whitespace?

> Nope, no confirmation. On my server Andy's message does have


> a proper signature, and yours does not. In your reply the
> "Like that" in the quoted text also follows an improper
> (two-dashes-only) signature separator.

That's what he was asking. But it's hard to say where the
problem really is; it doesn't (or didn't in the past) affect all
of my postings through Google Groups---if I recall correctly, it
only affected those transiting the company firewall where I was
before.

In general, between the moment the message leaves my machine,
and gets to your machine, it goes through a large number of
intermediate systems, at different levels. Any of them could be
guilty. All I know is that it isn't systematic; i.e. it has
never affected all of my postings.

> I do NOT believe that newsserver software does anything to the
> message contents. NewsREADER software does, undoubtedly.

As do firewalls, and possibly some transmission software.
Google Groups definitely has mangled message contents at times;
I remember a short time when it was reformatting my program
code.

--
James Kanze

Alf P. Steinbach

unread,
Oct 2, 2009, 3:55:55 AM10/2/09
to
* James Kanze:

It has.


>> I do NOT believe that newsserver software does anything to the
>> message contents. NewsREADER software does, undoubtedly.

Yeah.


> As do firewalls, and possibly some transmission software.
> Google Groups definitely has mangled message contents at times;
> I remember a short time when it was reformatting my program
> code.

It always does.


Cheers,

- Alf

Alf P. Steinbach

unread,
Oct 2, 2009, 3:56:55 AM10/2/09
to
* James Kanze:

No, you have never had proper signature delimiter in your Google-posted articles.

Cheers,

- Alf

Bo Persson

unread,
Oct 2, 2009, 11:31:56 AM10/2/09
to

It wasn't. :-)

BTW, I use terrible Outlook Express with OE Quotefix. I do see a space
in the real signature, even with Quotefix disabled.


Bo Persson


Bo Persson

unread,
Oct 2, 2009, 11:37:50 AM10/2/09
to

On closer examination, it seems like the space I was seeing might have
been Outlook Express' way of showing end of line. So it was OE
Quotefix that was smart enough to recognize the sig even without a
space. "Too forgiving"?

I take everything back! :-)


Bo Persson


Francesco S. Carta

unread,
Oct 2, 2009, 2:32:53 PM10/2/09
to
On 1 Ott, 23:21, "Francesco S. Carta" <entul...@gmail.com> wrote:

> Just out of curiosity, can someone confirm whether this very message,
> posted from GoogleGroups with a "-- " sig start below, actually
> arrives to other servers _with_ the trailing whitespace?

@ Everybody: thanks for taking place in this small survey.

@ GoogleGroups: please fix your signature mangling!

;-)

Have good time,
Francesco

0 new messages