POV-Ray : Newsgroups : povray.off-topic : C# 4.0 Default parameters : Re: C# 4.0 Default parameters Server Time
9 Oct 2024 18:19:40 EDT (-0400)
  Re: C# 4.0 Default parameters  
From: Mike Raiford
Date: 4 Feb 2009 12:42:30
Message: <4989d386$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.