Re: How to declare immutable struct outside of try catch and reference it later

2017-12-04 Thread kdevel via Digitalmars-d-learn
On Sunday, 3 December 2017 at 23:29:01 UTC, Basile B. wrote: On Sunday, 3 December 2017 at 22:33:40 UTC, kdevel wrote: On Sunday, 3 December 2017 at 14:58:03 UTC, Basile B. wrote: In this case i'd go for a typed pointer, e.g --- immutable struct Configuration { this(string){/*load some

Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread Basile B. via Digitalmars-d-learn
On Sunday, 3 December 2017 at 22:33:40 UTC, kdevel wrote: On Sunday, 3 December 2017 at 14:58:03 UTC, Basile B. wrote: In this case i'd go for a typed pointer, e.g --- immutable struct Configuration { this(string){/*load some file...*/} int value; } Configuration* config; void main()

Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread kdevel via Digitalmars-d-learn
On Sunday, 3 December 2017 at 14:58:03 UTC, Basile B. wrote: In this case i'd go for a typed pointer, e.g --- immutable struct Configuration { this(string){/*load some file...*/} int value; } Configuration* config; void main() { try config = new Configuration("config.sdl");

Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread Basile B. via Digitalmars-d-learn
On Sunday, 3 December 2017 at 05:49:54 UTC, Fra Mecca wrote: I have this code: Configuration conf = void ; try { conf = parse_config("config.sdl"); } catch (Exception e) { std.stdio.stderr.writeln("Error reading configuration file: ", e.msg); exit(1); }

Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread kdevel via Digitalmars-d-learn
On Sunday, 3 December 2017 at 14:16:42 UTC, kdevel wrote: int main () { try { real_main (); } catch (Exception e) { std.stdio.stderr.writeln(e.msg); return 1; } return 0; } ``` This is better: int main () { try { return real_main (); } catch

Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread kdevel via Digitalmars-d-learn
On Sunday, 3 December 2017 at 05:49:54 UTC, Fra Mecca wrote: I have this code: Configuration conf = void ; try { conf = parse_config("config.sdl"); } catch (Exception e) { std.stdio.stderr.writeln("Error reading configuration file: ", e.msg); exit(1); }

Re: How to declare immutable struct outside of try catch and reference it later

2017-12-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, December 03, 2017 05:49:54 Fra Mecca via Digitalmars-d-learn wrote: > I have this code: > Configuration conf = void ; > try { > conf = parse_config("config.sdl"); > } catch (Exception e) { > std.stdio.stderr.writeln("Error reading configuration > file:

How to declare immutable struct outside of try catch and reference it later

2017-12-02 Thread Fra Mecca via Digitalmars-d-learn
I have this code: Configuration conf = void ; try { conf = parse_config("config.sdl"); } catch (Exception e) { std.stdio.stderr.writeln("Error reading configuration file: ", e.msg); exit(1); } // other code function(value, conf); // end I get: