Signature of function

Discussion in 'C++' started by pauldepstein@att.net, Jul 25, 2008.

  1. Guest

    Hi all,

    I saw some code like this:



    unsigned short SomeFunc(unsigned short SomeNum, bool SomeBool, const
    SomeClass& SomeMem,
    bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned short)
    const)
    {
    // some code
    }


    I'm confused by the final parameter
    bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned short)
    const

    This parameter seems to have type pointer-to-function However,
    here, the parameter is pointer-to-function where the function in
    question is specific -- i.e the function in SomeClass called
    AmemberFunctionOfSomeClass

    This seems to me to contradict the whole idea of a parameter because
    the parameter in question is a pointer to a specific function not a
    pointer-to-function which varies according to the function that is
    input.

    Thanks for your help in understanding what is going on here,

    Paul Epstein
     
    , Jul 25, 2008
    #1
    1. Advertising

  2. Alp Mestan Guest

    Hi,

    On 25 juil, 04:19, wrote:
    > Hi all,
    >
    > I saw some code like this:
    >
    > unsigned short SomeFunc(unsigned short SomeNum, bool SomeBool, const
    > SomeClass& SomeMem,
    > bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned short)
    > const)
    > {
    > // some code
    >
    > }
    >
    > I'm confused by the final parameter
    > bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned short)
    > const
    >
    > This parameter seems to have type pointer-to-function However,
    > here, the parameter is pointer-to-function where the function in
    > question is specific -- i.e the function in SomeClass called
    > AmemberFunctionOfSomeClass
    >
    > This seems to me to contradict the whole idea of a parameter because
    > the parameter in question is a pointer to a specific function not a
    > pointer-to-function which varies according to the function that is
    > input.
    >
    > Thanks for your help in understanding what is going on here,
    >
    > Paul Epstein


    This parameter is a pointer to a member function of the "SomeClass"
    class and that returns a bool value and that takes a const unsigned
    short as parameter.
    AmemberFunctionOfSomeClass is just the name we give to the parameter,
    as "i" is the name of the integer argument in the following function
    declaration.
    void f(int i);
     
    Alp Mestan, Jul 25, 2008
    #2
    1. Advertising

  3. Guest

    On Jul 25, 11:19 am, wrote:
    > Hi all,
    >
    > I saw some code like this:
    >
    > unsigned short SomeFunc(unsigned short SomeNum, bool SomeBool, const
    > SomeClass& SomeMem,
    > bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned short)
    > const)
    > {
    > // some code
    >
    > }
    >
    > I'm confused by the final parameter
    > bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned short)
    > const
    >
    > This parameter seems to have type pointer-to-function However,
    > here, the parameter is pointer-to-function where the function in
    > question is specific -- i.e the function in SomeClass called
    > AmemberFunctionOfSomeClass


    The edited code you post might differ from that you're trying to
    understand subtly. I suspect you're expected to nominate any one of
    the member functions of that specific class that match that calling
    signature.

    > This seems to me to contradict the whole idea of a parameter because
    > the parameter in question is a pointer to a specific function not a
    > pointer-to-function which varies according to the function that is
    > input.


    That's why I suspect it's not to a specific function, but to any
    member function of a specific class.

    > Thanks for your help in understanding what is going on here,
    >
    > Paul Epstein


    Tony
     
    , Jul 25, 2008
    #3
  4. Guest

    On Jul 25, 1:06 pm, wrote:
    > On Jul 25, 11:19 am, wrote:
    >
    >
    >
    >
    >
    > > Hi all,

    >
    > > I saw some code like this:

    >
    > > unsigned short SomeFunc(unsigned short SomeNum, bool SomeBool, const
    > > SomeClass& SomeMem,
    > > bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned short)
    > > const)
    > > {
    > >     // some code

    >
    > > }

    >
    > > I'm confused by the final parameter
    > > bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned short)
    > > const

    >
    > > This parameter seems to have type pointer-to-function     However,
    > > here, the parameter is pointer-to-function where the function in
    > > question is specific -- i.e the function   in SomeClass called
    > > AmemberFunctionOfSomeClass

    >
    > The edited code you post might differ from that you're trying to
    > understand subtly.  I suspect you're expected to nominate any one of
    > the member functions of that specific class that match that calling
    > signature.
    >
    > > This seems to me to contradict the whole idea of a parameter because
    > > the parameter in question is a pointer to a specific function  not a
    > > pointer-to-function which varies according to the function that is
    > > input.

    >
    > That's why I suspect it's not to a specific function, but to any
    > member function of a specific class.
    >
    > > Thanks for your help in understanding what is going on here,

    >



    Thanks to all the responses. I'm restricted a bit because this is
    confidential code so I have to change the names.
    SomeClass has a member function called AmemberFunctionOfSomeClass

    What respondents seem to be saying is that this fact is irrelevant and
    I could replace AmemberFunctionOfSomeClass by any other name in the
    original code (just like void f(int i); could be replaced by void
    f(int j); or void f(int);

    Paul Epstein
     
    , Jul 25, 2008
    #4
  5. James Kanze Guest

    On Jul 25, 5:03 am, Sam <> wrote:
    > writes:


    > > I'm confused by the final parameter
    > > bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned short)
    > > const


    > > This parameter seems to have type pointer-to-function However,


    > No. This is a pointer to a class method, not a function.


    The correct term, in C++, is pointer to member function. The
    C++ language doesn't have methods. (In fact, of course, the
    word is widely used, with varying meanings. Because of the
    varying meanings, however, it's best avoided. Also, the word
    leads to confusion with software engineering methods, like the
    use of CRC cards or UML diagrams.)

    --
    James Kanze (GABI Software) email:
    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
     
    James Kanze, Jul 25, 2008
    #5
    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. JJBW
    Replies:
    1
    Views:
    10,202
    Joerg Jooss
    Apr 24, 2004
  2. sqweek
    Replies:
    2
    Views:
    405
    Charles Rapp
    Jan 13, 2006
  3. Replies:
    1
    Views:
    394
  4. Gustavo Narea
    Replies:
    14
    Views:
    869
    Gustavo Narea
    Feb 16, 2009
  5. daniel rich
    Replies:
    5
    Views:
    311
    daniel rich
    Nov 14, 2012
Loading...

Share This Page