POV-Ray : Newsgroups : povray.off-topic : C++ questions : Re: C++ questions Server Time
7 Sep 2024 15:26:20 EDT (-0400)
  Re: C++ questions  
From: Darren New
Date: 26 Sep 2008 15:30:23
Message: <48dd384f$1@news.povray.org>
Warp wrote:
>   Isn't this usually handled with callback interfaces (in OO languages)
> rather than function pointers?

Only in languages that don't support pointers to member functions. In 
languages with closures or pointers to member functions, no. Just like 
in a language without pointers at all, the way you do callbacks is to 
redefine the function at link-time and then do a big switch statement.

C#, for example, has the "observer" design pattern built into the 
language as "delegates" or "events", accepting multiple pointers to 
member functions and letting the owner "invoke" all the methods pointed to.

Ruby and Smalltalk and all those pass around "blocks" for this 
functionality. Python passes around lambdas. LISP passes around 
closures. They're all essentially the same sort of thing, with ever so 
slightly different implementations, but all basically "a block of code 
with a pointer to an object's context".

-- 
Darren New / San Diego, CA, USA (PST)


Post a reply to this message

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