How does D improve design practices over C++?

Janderson ask at me.com
Sun Nov 9 19:32:55 PST 2008


Christopher Wright wrote:
> Michel Fortin wrote:
>> On 2008-11-07 02:42:20 -0500, Walter Bright 
>> <newshound1 at digitalmars.com> said:
>>
>>> The difference between D delegates and boost::bind for member 
>>> functions is that D delegates bind to the specific virtual function 
>>> when the delegate is created, while boost::bind binds when the 
>>> delegate is called. The former is, of course, more efficient when the 
>>> delegate gets called more than once.
>>
>> But the later makes it possible to call the same member function on 
>> various object instances (which may resolve to different code for 
>> virtual functions). I find that capability lacking in D.
> 
> You can do it in D, but only with templates. And it's ugly.
> 
> I must admit, I've never encountered a situation in which I wanted a 
> pointer to a member function. What situations did you encounter this in? 
> Why were, say, interfaces insufficient?

I've found it useful to call different object instances with the same 
member function pointer on very few occasions in C++.  However I'd point 
out that interfaces in C++ mean you have to change another file (or use 
a boltin).   So sometimes its difficult to modify or even wrap another 
API's class in that way.  In these cases (and others) delegates (or 
member function pointers) are better then interfaces.

-Joel



More information about the Digitalmars-d mailing list