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

Discussion in 'C++' started by Victor Bazarov, Sep 30, 2009.

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

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Sep 30, 2009
    #1
    1. Advertising

  2. Victor Bazarov

    James Kanze Guest

    On Sep 30, 9:51 pm, Victor Bazarov <> 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
     
    James Kanze, Oct 1, 2009
    #2
    1. Advertising

  3. 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
     
    Marcel Müller, Oct 1, 2009
    #3
  4. Marcel Müller wrote:
    > 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?


    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.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Oct 1, 2009
    #4
  5. On 1 Ott, 22:35, Andy Champ <> 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
     
    Francesco S. Carta, Oct 1, 2009
    #5
  6. Victor Bazarov

    Bo Persson Guest

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

    Francesco S. Carta wrote:
    > On 1 Ott, 22:35, Andy Champ <> 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?


    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
     
    Bo Persson, Oct 1, 2009
    #6
  7. Francesco S. Carta wrote:
    > On 1 Ott, 22:35, Andy Champ <> 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


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

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Oct 1, 2009
    #7
  8. * Bo Persson:
    > Francesco S. Carta wrote:
    >> On 1 Ott, 22:35, Andy Champ <> 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?

    >
    > It does, "proven" by the fact that your signature is removed in this
    > reply.
    >
    >
    > I'm using the news.individual.net NNTP server.


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

    Consider installing OE QuoteFix, if you haven't.


    Cheers,

    - Alf
     
    Alf P. Steinbach, Oct 1, 2009
    #8
  9. Victor Bazarov

    James Kanze Guest

    On Oct 1, 9:35 pm, Andy Champ <> 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, Oct 2, 2009
    #9
  10. Victor Bazarov

    James Kanze Guest

    On Oct 1, 10:40 pm, Victor Bazarov <> wrote:
    > Francesco S. Carta wrote:
    > > On 1 Ott, 22:35, Andy Champ <> 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
     
    James Kanze, Oct 2, 2009
    #10
  11. * James Kanze:
    > On Oct 1, 10:40 pm, Victor Bazarov <> wrote:
    >> Francesco S. Carta wrote:
    >>> On 1 Ott, 22:35, Andy Champ <> 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.


    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, Oct 2, 2009
    #11
  12. * James Kanze:
    > On Oct 1, 9:35 pm, Andy Champ <> 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.)


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

    Cheers,

    - Alf
     
    Alf P. Steinbach, Oct 2, 2009
    #12
  13. Victor Bazarov

    Bo Persson Guest

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

    Victor Bazarov wrote:
    > Francesco S. Carta wrote:
    >> On 1 Ott, 22:35, Andy Champ <> 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

    >
    > 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).
    >
    > V


    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, Oct 2, 2009
    #13
  14. Victor Bazarov

    Bo Persson Guest

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

    Bo Persson wrote:
    > Victor Bazarov wrote:
    >> Francesco S. Carta wrote:
    >>> On 1 Ott, 22:35, Andy Champ <> 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

    >>
    >> 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).
    >>
    >> V

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


    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
     
    Bo Persson, Oct 2, 2009
    #14
  15. On 1 Ott, 23:21, "Francesco S. Carta" <> 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
    --
    Francesco S. Carta, hobbyist
    http://fscode.altervista.org
     
    Francesco S. Carta, Oct 2, 2009
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    12
    Views:
    737
    fluden
    Feb 11, 2005
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,228
    Smokey Grindel
    Dec 2, 2006
  3. grocery_stocker
    Replies:
    10
    Views:
    660
    Keith Thompson
    May 25, 2005
  4. SG
    Replies:
    0
    Views:
    195
  5. Victor Bazarov
    Replies:
    3
    Views:
    193
    Jorgen Grahn
    May 29, 2013
Loading...

Share This Page