pointers to member functions - can they point to operators ?

Discussion in 'C++' started by Stephen Howe, Dec 1, 2012.

  1. Stephen Howe

    Stephen Howe Guest

    Hi

    Is is possible to set a pointers to member function to point to an operator - implemented as a class member obviously. I suppose this hinges on whether the address operator can be applied to a class member operator.

    It is unusual, I have not seen it done but that does not mean it is impossible.

    Thanks

    Stephen Howe
     
    Stephen Howe, Dec 1, 2012
    #1
    1. Advertising

  2. Stephen Howe

    W Karas Guest

    On Saturday, December 1, 2012 6:03:42 PM UTC-5, Stephen Howe wrote:
    > Hi
    >
    >
    >
    > Is is possible to set a pointers to member function to point to an operator - implemented as a class member obviously. I suppose this hinges on whether the address operator can be applied to a class member operator.
    >
    >
    >
    > It is unusual, I have not seen it done but that does not mean it is impossible.
    >
    >
    >
    > Thanks
    >
    >
    >
    > Stephen Howe


    g++ compiles this code:


    class A { };

    A operator + (A a1, A a2);

    typedef A (*Fr)(A, A);
    Fr foo(void) { return(operator +); }
     
    W Karas, Dec 2, 2012
    #2
    1. Advertising

  3. On 12/1/12 6:03 PM, Stephen Howe wrote:
    > Hi
    >
    > Is is possible to set a pointers to member function to point to an operator - implemented as a class member obviously. I suppose this hinges on whether the address operator can be applied to a class member operator.
    >
    > It is unusual, I have not seen it done but that does not mean it is impossible.
    >
    > Thanks
    >
    > Stephen Howe
    >

    The member functions like class::eek:perator+(class) are just like any
    other member functions, they just have the syntactic sugar method of
    calling them. You can take their address or call them with explicit call
    syntax.
     
    Richard Damon, Dec 2, 2012
    #3
  4. Stephen Howe

    Öö Tiib Guest

    On Sunday, 2 December 2012 01:03:42 UTC+2, Stephen Howe wrote:
    > Hi
    >
    > Is is possible to set a pointers to member function to point to an operator - implemented as a class member obviously. I suppose this hinges on whether the address operator can be applied to a class member operator.


    Certainly.

    > It is unusual, I have not seen it done but that does not mean it is impossible.


    Operators are meant to achieve most convenient syntax.
    Syntax of pointers-to-member-functions on the other hand is most ugly.
    It is rare case that does such sugar -> ugly switch and wins something.
     
    Öö Tiib, Dec 2, 2012
    #4
    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. Blue Ocean

    Pass pointers or the things they point to

    Blue Ocean, Jul 10, 2004, in forum: C Programming
    Replies:
    8
    Views:
    309
    Dan Pop
    Jul 12, 2004
  2. Dave Rudolf
    Replies:
    1
    Views:
    317
    Kai-Uwe Bux
    May 17, 2006
  3. Hamish
    Replies:
    3
    Views:
    605
    Alf P. Steinbach
    Jan 25, 2008
  4. paul
    Replies:
    8
    Views:
    744
    Alf P. Steinbach
    Apr 30, 2009
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,413
    Saraswati lakki
    Jan 6, 2012
Loading...

Share This Page