Linked Lists in General ( previously Functions as Arguments)

Does anyone know a good source of info for passing functions as arguments? Thanks
Last edited on
that is not possible... it doesnt work that way. It's like answering a question with a question, doesnt make sense.

Why do you want to do this?
Well you can pass pointers to functions around, a quick search turned up this: http://www.newty.de/fpt/index.html
closed account (zb0S216C)
I assume you mean a pointer/reference to a function?

1
2
typedef void (*Function)(); // Pointer to a function
typedef void (&Function)(); // Reference to a function 

Here's a good source: http://www.cprogramming.com/tutorial/function-pointers.html

Wazzak
There are also function objects to help you out. The old C++03 uses the ptr_fun, mem_fun, and mem_fun_ref objects to help you out (see the <functional> header).

C++11 chucks all that and gives you the std::function object to use.

What they do is wrap a function (function pointers, class member functions, lambdas, etc) and you can then treat it like any normal object.

Hope this helps.
Thanks, thats exactly what I mean. I'm trying to replicate the list container, so I would like to pass a function pointer to a sort method.
that makes no sense at all...
Sure it does :), but I think your name says it all.

Edit: I changed the name of this thread, but I keep answering my questions while I type :)
Last edited on
That's the idea.

1
2
3
#include <algorithm>
#include <functional>
#include <vector> 
1
2
3
bool is_sort_less_than( int x );
vector <int> xs;
std::stable_sort( xs.begin(), xs.end(), std::function <bool (int)> ( &is_sort_less_than ) );
Topic archived. No new replies allowed.