Jump to content
  • Advertisement

Archived

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

Toolmaker

WTF are functors, and how do they work?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 function

new_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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 function

new_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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!