![]() |
| ||
| Help on function pointers I get an error on the following code. It seems I can“t use a function which belongs to a class as an argument for "genericfunction". Any help on how to overcome the problem would be great. Thanks. //Main |
| ||
| Re: Help on function pointers No, you can't, because member functions take an extra, hidden, argument this. You might want to check out functors, which would solve your problem! (While you are at it, the entire Function Pointer Tutorials site is worth a good perusal.) Hope this helps. |
| ||
| Re: Help on function pointers So functors are the way to go? Never would have guessed! Thanks for your reply and the reference to the tutorial. |
| ||
| Re: Help on function pointers Hmm, as I re-read your code your "generic function" seems to me to be very un-generic --at least in the C++ sense of the word. Hence my suggestion for functors. If you really want to use function pointers directly you will have to figure some other way to fix it. Otherwise you will need to implement it in terms of C++ generics. Here's an example: #include <iostream> Hope this makes things a little clearer with functors. Alas, I think I didn't really answer your original problem. |
| All times are GMT -4. The time now is 12:30 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC