Reputation: 35
I am working on a simple porting project where some .NET api code need to be converted to C++ code. There is no GUI here. I am little confused on deciding the best way of converting delegates. It will be helpful if you share your thoughts to help me decide whether to simply replace delegates with function pointers or some Observer pattern should be implemented. For some reasons I cannot use any third party library like Boost. So I prefer something pretty simple to implement yet quite efficient and good considering from design concept.
Thanks.
Upvotes: 2
Views: 356
Reputation: 35
I made my own event handling system. It is pretty simple. I just followed very basics of C++. I think ppl would enjoy more liberty once C++0x is confirmed. For now I believe it is quite preferable.
Upvotes: 0
Reputation: 14603
Try following, a new update is on the way as well. You do not need to add lots of files to your project.
http://sourceforge.net/projects/eventchain/
Upvotes: 0
Reputation: 54290
Don Clugston's Fast Delegates are a popular choice for delegates in C++. They are far from simple, but you should be able to easily copy and paste the code into your project. I'm not an expert on C# delegates, so I'm not sure how easily they'll port from there, but they are efficient, and should cover most use cases.
Upvotes: 3
Reputation: 65639
How up to date is your compiler? Does it have C++0x features? And can you use the C++ std library? If you have C++0x and can use the STL, then std::function* is the most identical to a C# delegate. Otherwise, you'll either have to use function pointers or roll your own observer pattern.
*Identical to boost function, but for some reason you can't use boost.
Upvotes: 1