What is wrong here? Error: cannot cast int to SYSTEMTIME

Spacen Jasset spacenjassset at yahoo.co.uk
Tue Oct 23 12:33:38 PDT 2007


BCS wrote:
> Reply to Spacen,
> 
>> Digital Mars D Compiler v1.015
>>
>> Neither of these lines will compile and give: Error: cannot cast int
>> to SYSTEMTIME
>>
>> without a line number. How might I get this to work?
>>
>> import std.date;
>>
>> //long utc_time1 = std.date.getUTCtime();
>>
>> void main()
>> {
>> //static long utc_time1 = std.date.getUTCtime();
>> }
>> Regards,
>> Jason
> 
> For the first line, do this:
> 
> utc_time1 = std.date.getUTCtime();
> static this(){long utc_time1 = std.date.getUTCtime();}
> 
> For the second drop the static (if it isn't actualy in main, you will 
> have to do somthing else)
> 
> The issue is that D doesn't allow runtime initializers for non stack 
> variables.
> 
> For the static function variable one you might be able to get away with 
> this:
> 
> template T(char[] str, A...)
> {
>   long v;
>   static this(){v = mixin(str);}
> }
> 
> 
> void fn()
> {
>   alias T!("std.date.getUTCtime()", __FILE__, __LINE__).v utc_time1;
> }
> 
> 
> there will be one version of T!(...).v for each distinct "...". Note, if 
> you put this in a templated function, make sure you put pass on the 
> template args or things get strange.
> 
> 
Ah ok. I need to read up on this. The code I was intending to use in 
that manner was for testing. Presumably the way is to create a class and 
use objects.

Thanks for the assistance.


More information about the Digitalmars-d-learn mailing list