POV-Ray : Newsgroups : povray.off-topic : C++ questions : Re: C++ questions Server Time
7 Sep 2024 09:21:19 EDT (-0400)
  Re: C++ questions  
From: Warp
Date: 26 Sep 2008 09:34:51
Message: <48dce4fb@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> Warp wrote:
> > Invisible <voi### [at] devnull> wrote:
> >> Pointers to members?
> > 
> >   You don't need them.

> That's what I was pretty much hoping, yeah.

> Looks like it would only be useful for some pretty obscure situations...

  They are useful in certain situations, but those situations are so rare
and usually so advanced, that even very experienced C++ programmers basically
never need them.

  I once created a command-line parameter interpreter which was used like
this (extremely simplified):

class MyCLI: public CommandLineInterpreter
{
    void inputFile() { ... }

 public:
    MyCLI()
    {
        // registerCLParameter() is a function in the base class.
        registerCLParameter("input", &inputFile);
    }
};

  Basically this meant that when the interpreter encountered the command-line
parameter "-input", it would call the 'inputFile()' method I defined above.
This uses method pointers.

  (The actual implementation is quite complicated because there are some
issues about a base class calling a derived class method through a method
pointer, but with template magic it's possible to do this portably and
safely.)

-- 
                                                          - Warp


Post a reply to this message

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