Problem: Cannot create class out of nothing using witchcraft

DoctorCaptain garble at harble.com
Wed Oct 16 12:06:34 PDT 2013


On Wednesday, 16 October 2013 at 18:47:25 UTC, Benjamin Thaut 
wrote:
> Am 16.10.2013 16:08, schrieb Benjamin Thaut:
>> Am 16.10.2013 10:40, schrieb DoctorCaptain:
>>>
>>> http://dpaste.dzfl.pl/07b20d75
>>>
>>> Note the use of typeof() to get the type of the elements at 
>>> each index
>>> of members, to generate a type on which a constructor can be 
>>> called to
>>> instantiate the elements at each index of members. Magic.
>>
>> There is actually a easier way to instanciate the elements. 
>> Just do "new
>> T[i]();" no need for typeof.
>>
>>
>
> I'm actually wrong. "new T[i]()" will not work because the 
> compiler will think it is a array allocation. You actually have 
> to use new typeof(member[i])();
>
> I created a example which generates individual class members 
> for each of the arguments bassed to GrabBagT:
>
> http://dpaste.dzfl.pl/eef2edec

AWW you posted that while I was writing my latest novel. So T[i] 
doesn't work? I guess I shouldn't have opened my eyes this 
morning. In any case, typeof() DOES work, so as long as there is 
a way to extract the type, we're good.

I am extremely pleased it's actually possible to get individual 
data members like I was originally attempting to do. I'm likely 
not going to actually do this, as your T members; solution is 
cleaner, but I'm glad it's not just arbitrarily impossible.

Thank you so much!


More information about the Digitalmars-d-learn mailing list