Polymorphism in regular variadic function

Bill Baxter dnewsgroup at billbaxter.com
Tue Dec 5 17:46:42 PST 2006


Jarrett Billingsley wrote:
> "Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
> news:el52bq$2dcb$1 at digitaldaemon.com...
>> Thanks Jarrett,
>> This TypeInfo_Class thing seems to be undocumented.
>>
>> Incidentally it's a piece of cake with a variadic template, I just wanted 
>> to see try it with a regular function first before going all templatey.
>>
>> I haven't tried your code, but it seems like your cast to Object in the 
>> second suggestion is not going to be safe if the thing really isn't an 
>> Object.  The following cast to Foo will try to do some vtable stuff I 
>> guess, and that could result in a bad memory access, no?
> 
> Hmm.. I don't think it should.  TypeInfo_Class is, well, the typeinfo for a 
> class, which all derive from Object, so getting the param as an Object 
> shouldn't be a problem, should it?

Oh, I see,  I didn't realize the TypeInfo_Class bits applied to the 
second suggestion also.

   TypeInfo ti = _arguments[i];
   TypeInfo_Class tic = cast(TypeInfo_Class)ti;
   if(tic)
   {
       Object o = va_arg!(Object)(_argptr);
       Foo f = cast(Foo)o;
       ..

So yeh, that does look like it would work, except for, as you say, the 
fact that it doesn't...  :(

--bb



More information about the Digitalmars-d-learn mailing list