Archived

This topic is now archived and is closed to further replies.

WTF are functors, and how do they work?

This topic is 5453 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Well, as the title says, what are they, and how do they work? A few good examples are welcome, aswell as a good tutorial on them. I didn''t understand the stuff on www.sgi.com about them. In case you wanna know,someone told me it would be usefull to implement them in my win32 wrapper, instead of static functions. Toolmaker
-Earth is 98% full. Please delete anybody you can.

Share on other sites
I assume that you spelled wrong and are talking about functions?
If you are look below other wise forget this post.
--------------------------------
Functions are just as they sound, they carry out commands, etc.
For example:
int new_file(char *filename, char ipt[80]){   ofstream datafile001( filename );   datafile001 << ipt1 << endl;   datafile001.close();   return(1);}////////////In your Game_Init functionnew_file("test.txt", "This is a test");
Tutorials would be good at http://www.functionx.com/
you can find what your looking for easily.

Share on other sites
Here''s a good tutorial on functors.

Share on other sites
summary: functor are objects with an operator() so they can be called like functions. The advantage is that they can have infromation associated with that object.

most common use to to write a mem_fun() functor.

Share on other sites
quote:
Original post by demonrealms
I assume that you spelled wrong and are talking about functions?
If you are look below other wise forget this post.
--------------------------------
Functions are just as they sound, they carry out commands, etc.
For example:
int new_file(char *filename, char ipt[80]){   ofstream datafile001( filename );   datafile001 << ipt1 << endl;   datafile001.close();   return(1);}////////////In your Game_Init functionnew_file("test.txt", "This is a test");
Tutorials would be good at http://www.functionx.com/
you can find what your looking for easily.

No he didn''t spell it incorrectly, "functors" do exist you know.

Share on other sites
In the C++ sense they are typesafe callbacks that work on member functions or regular function. Use Boost::Function with Boost::Bind to make them.

They mean something entirely different in ML.

Oh, and you still need static functions for Win32 callbacks.

[edited by - antareus on October 20, 2003 9:55:51 PM]

Share on other sites
Well, I am not looking for callback functions . I am using oluseyi''s way of having a windows class and such. I am currently writing a pretty large wgBaseWindow class and I wanted to use functors for that. So I can do this:

class ExitButton{public:     long Click(wgBaseWindow *Owner, wgBaseWindow *Me, WPARAM wParam, LPARAM lParam);};

And then pass the Click function into the message line. Is it possible that way?

Toolmaker

-Earth is 98% full. Please delete anybody you can.

Share on other sites
Don''t know what you mean by message line, but to
connect events, you might find libsigc++ useful.

Share on other sites
If have a special RegisterEvent function to get fn pointers. However, the functions need to be static. How do I make then non-static, so I can just use class members without having the function static.

Toolmaker

Share on other sites
I just explained what you had to do but you shot back "I don''t need callbacks."

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 10
• 14
• 10
• 25
• Forum Statistics

• Total Topics
632647
• Total Posts
3007640
• Who's Online (See full list)

There are no registered users currently online

×