Thread overview | |||||
---|---|---|---|---|---|
|
January 25, 2019 The default can be used as a property is very bad design. | ||||
---|---|---|---|---|
| ||||
OH NO ! sample code: ```D import std.stdio; struct Config { string test = "aaa"; string test2 = "bbb"; } Config config() { Config conf; return conf; } class Test { void func1() { string config; string testConfig = config().test; writeln(testConfig); } } ``` build error: ```shell osx:test zoujiaqing$ dmd config.d config.d(22): Error: function expected before (), not config of type string ``` |
January 25, 2019 Re: The default can be used as a property is very bad design. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian | On Friday, 25 January 2019 at 02:09:29 UTC, Brian wrote: > OH NO ! This has nothing to do with property. It is just a local variable - those always take precedence over global ones. Use the module scope operator to use one outside; the leading dot: > string testConfig = config().test; string testConfig = .config().test; // note the leading dot |
Copyright © 1999-2021 by the D Language Foundation