|
|
Warp wrote:
> Mike Raiford <"m[raiford]!at"@gmail.com> wrote:
>> At least in C# you can't do function pointers.
>
> There are situations where function pointers are actually useful.
> Here's one actual example which I have used in the past (simplified here,
> of course):
>
> class MyCLP: public CommandLineParser
> {
> bool debugParamHandler(const std::string&)
> {
> // do whatever here
> }
>
> public:
> MyCLP()
> {
> setOptionHandler("debug", &MyCLP::debugParamHandler,
> "The short description of the -debug parameter");
> }
> };
>
C# uses delegates, instead. Similar functionality Not as ugly to
declare. Function pointer syntax can get ugly.
>
> std::sort(array.begin(), array.end(), objectComparator);
>
Again, very similar to the predicates used in C#'s extension functions,
which take delegates.
>
> It's possible to create an object which behaves like such a function
> (a functor object), but it's more writing.
>
Which is essentially a delegate :)
I was mainly alluding to the messiness of declaring function pointers.
C# does have a mechanism to do what you've described, though.
--
~Mike
Post a reply to this message
|
|