DMD 0.166 release

Derek Parnell derek at nomail.afraid.org
Thu Aug 31 21:40:34 PDT 2006


On Thu, 31 Aug 2006 20:32:01 -0700, Walter Bright wrote:

> Derek Parnell wrote:
>> Damn! I didn't know that. What's the rationale for such a seemingly
>> arbitrary restriction?
> 
> No virtual functions for structs!

Ok, that meant nothing to me until I translated it from the OO jargon. Here
is my attempt at converting Walter's answer into human speech ;-)

The 'format' function examines each parameter supplied to it in order to
convert it into some form of string. When it comes to a class object, it
casts the object instance to 'Object' and then calls Object.toString(),
which through the magic of 'virtual functions' actually gets around to
calling the parameter's own toString() method if it exists. 'virtual
functions' is the mechanism in which derived classes can have their methods
called via reference to their parent class. Now structs are not derived
from anything and thus there cannot be a generic toString() method in a
struct parent. So the 'format' function doesn't know which struct
toString() to call and it throws the exception instead. 

I guess that when D eventually gets runtime reflection we will be able to
improve 'format' to check if the struct parameter passed to it has a
toString method and thus call it.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
1/09/2006 2:29:34 PM



More information about the Digitalmars-d-announce mailing list