Anyone know why this CTFE isn't working?

Rory McGuire rmcguire at neonova.co.za
Fri Jul 16 03:13:34 PDT 2010


On Fri, 16 Jul 2010 12:05:02 +0200, Jonathan M Davis  
<jmdavisprog at gmail.com> wrote:

> On Friday 16 July 2010 02:46:48 Rory McGuire wrote:
>> import std.stdio;
>>
>> struct State {
>>   string s; string getString() { return s; }
>>   static State opCall(string s) {
>>   State ret;
>>   ret.s = s;
>>   return ret;
>>   }
>> }
>>
>> void main() {
>>   auto s = State("adf");
>>   pragma(msg, s.getString());
>> }
>
> Make s an enum and it'll work. As it is, it's a local variable created at
> runtime rather than a constant at compile-time. So, use
>
> enum s = State("adf");
>
>
> - Jonathan M Davis

Thanks

worked


More information about the Digitalmars-d-learn mailing list