POV-Ray : Newsgroups : povray.off-topic : C# 4.0 Default parameters : Re: C# 4.0 Default parameters Server Time
9 Oct 2024 18:19:31 EDT (-0400)
  Re: C# 4.0 Default parameters  
From: Warp
Date: 4 Feb 2009 12:51:55
Message: <4989d5bb@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> I think better would be the way you wind up having to do it in Java - you 
> have a class that implements a "parse this" method for each possible 
> argument to be parsed, and the parser has a map from "-debug" to an instance 
> of the class that parses the debug parameter.  So you have one subclass for 
> each parser function.  Ugly, but not as bad as a giant switch statement.

  Actually that's the most cumbersome solution (especially if you wanted
all the options inside one single class, rather than having one class per
option, which makes retrieving the values of the options more laborious)
and the one which requires most extra writing.

  Yes, I considered many possible solutions when I implemented that command
line parser class, and found that the function (or rather method) pointer
solution was the best, from the usage point of view. The classes derived
from the parser class can be made simple, short and easy to read.

> FWIW, a delegate *is* an object that behaves like a function (your "functor 
> object").  You write something like

  Does it also work for member functions?

  Member function pointers are a bit complicated in C++, but they can
be useful (as in my command line parser example). Obviously to call a
member function of a class through a pointer you need also the object for
which the function is called. The syntax for calling such a function is:

    object.*functionPointer(parameters);

-- 
                                                          - Warp


Post a reply to this message

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