Struct - static initialization "on-the-fly"

Marek Janukowicz marek at janukowicz.net
Tue Aug 20 15:47:10 PDT 2013


In this program:

import std.stdio, std.json;

void main () {
  JSONValue jsonSet;
  jsonSet.type = JSON_TYPE.OBJECT;
  JSONValue a = { type: JSON_TYPE.STRING, str: "abcde" }; // This work
  jsonSet.object["a"] = a;
  jsonSet.object["b"] = { type: JSON_TYPE.STRING, str: "jjf" }; // THIS LINE
}

marked line will not compile failing with:
json.d(8): Error: found ':' when expecting ';' following statement 

Is there any way to selectively initialize a struct while using it as AA 
value? The way I set "a" key works, but requires two lines instead of one 
and I have many such elements to set. I can't initialize all members of 
JSONValue, because there are many and I only need those two.

-- 
Marek Janukowicz


More information about the Digitalmars-d-learn mailing list