VC++ Delegate Options

  • Thread starter Thread starter Rob Schieber
  • Start date Start date
R

Rob Schieber

Hey,

I need to utilize function pointers in my MFC application. I was
wondering what the best approach is. Im a C# developer, so I'm farily
comofortable using delegates.

So far I've found a library called boost.function
http://www.boost.org/doc/html/function.html which looks easy to use
simillar to delegates. Just wondering if there's anything better out there.
 
Rob Schieber said:
Hey,

I need to utilize function pointers in my MFC application. I was
wondering what the best approach is. Im a C# developer, so I'm farily
comofortable using delegates.

So far I've found a library called boost.function
http://www.boost.org/doc/html/function.html which looks easy to use
simillar to delegates. Just wondering if there's anything better out
there.

If you want something like delegates, boost::function is a good way to go.

-cd
 
Rob said:
So far I've found a library called boost.function
http://www.boost.org/doc/html/function.html which looks easy to use
simillar to delegates. Just wondering if there's anything better out
there.

If you're interested about the internals of implementing delegates in
native C++, you may want to take a look at my article at
http://tweakbits.com/articles/events/index.html

No, I'm not saying it's better than boost::function. However, my article
provides an in-depth explanation of how these delegate (closure)
templates work internally. In fact, I provided two independent solutions
for the same problem. When I started implementing it, boost::function
did not exist, or at least was not publically available yet. The best
thing about my implementation is that it is very small. It only uses 2
pointers, and therefore sizeof(event) = 2 * sizeof(void*), which is the
theoretical minimum (an event must store the address of both the member
function and the object as well). I don't know how it compares to
boost::function's memory requirements, but these days it's not that
important anymore.

Boost has a very nice, generally accepted, multi-platform
implementation, with a wide user-base. I encourage you to use that. My
opinion is that if something is implemented in STL or boost, and it
works for me, I could hardly find a reason not to use it.

Tom
 
Back
Top