Signature of function

P

pauldepstein

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
 
A

Alp Mestan

Hi,

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);
 
T

tony_in_da_uk

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
 
P

pauldepstein

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.


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


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
 
J

James Kanze

(e-mail address removed) writes:
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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top