pointers

S

sundaram.bhuvana

hi
i would like to know about the meaning of the following code

int select(int(*fn)(int,int),int x,int y)

what is the meaning of it
 
D

David Côme

hi
i would like to know about the meaning of the following code

int select(int(*fn)(int,int),int x,int y)

what is the meaning of it


int(*fn)(int,int) is a pointeur to a fonction who return a int and who
takes 2 ints for parameters
 
A

Abhishek Padmanabh

int(*fn)(int,int) is a pointeur to a fonction who return a int and who  
takes 2 ints for parameters

... and select is a function that takes that takes 3 arguments, first
being the pointer to the function as described by David above and 2
integers and has a return type : int.
 
H

Howard

i would like to know about the meaning of the following code
int select(int(*fn)(int,int),int x,int y)

It's a function (select), which returns an int, and which takes three
parameters; the last two parameters are ints (x and y), and the first
parameter is a pointer to a function (fn) which returns an int and takes two
int parameters.

(Personally, I'd prefer to create a typedef for the function pointer, and
put that type in the parameter list, just to make it more readable.)

-Howard
 
D

Daniel T.

It's a function (select), which returns an int, and which takes three
parameters; the last two parameters are ints (x and y), and the first
parameter is a pointer to a function (fn) which returns an int and takes two
int parameters.

(Personally, I'd prefer to create a typedef for the function pointer, and
put that type in the parameter list, just to make it more readable.)

And since this is a C++ newsgroup, I think making it a template would
be more approprate. :)
 
D

Daniel T.

Dave Rahardja said:

The same way it is done in the standard library. Note that 'fn' in the
above satisfies the Binary Function concept and could be used in (for
example) std::transform.

template < typename Fn >
int select( Fn fn, int x, int y )
{
// now use 'fn' under the assumption that it takes two ints as
// arguments and returns an int. For example like this:

return fn( x, y );
}
 
C

Carlo Milanesi

(e-mail address removed) ha scritto:
hi
i would like to know about the meaning of the following code

int select(int(*fn)(int,int),int x,int y)

It is a declaration of the function "select", as a function taking three
formal parameters, "fn", "x", and "y", and returning an "int".
The first of such parameters ("fn") is a pointer to a function that
takes two parameters, both of type "int", and returns an "int". The
second and third parameters ("x" and "y") are of type "int".
 

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

Forum statistics

Threads
474,184
Messages
2,570,976
Members
47,536
Latest member
MistyLough

Latest Threads

Top