Is it possible to modify shared struct array in a function.
Arun Chandrasekaran
aruncxy at gmail.com
Fri Feb 8 06:50:32 UTC 2019
On Friday, 8 February 2019 at 04:51:08 UTC, Sudhi wrote:
> On Friday, 8 February 2019 at 04:30:23 UTC, Arun Chandrasekaran
> wrote:
>> [...]
>
>
> My example code was wrong. Below is the right one.
>
> struct Company
> {
> string name;
> string location;
> }
>
> struct Racks
> {
> int number;
> int location;
> }
>
> struct Metadata
> {
> string name;
> Company[] companies;
> Racks[] racks;
> }
>
> struct Item
> {
> Metadata[] met;
> int count;
> }
>
> shared (Item) item;
>
> void main()
> {
> updateMetadata();
> }
>
> void updateMetadata()
> {
> Company company;
> company.name = "Hello";
> company.location = "Bangalore";
> item.met.companies ~= company;
> import std.stdio: writeln;
> writeln(item);
> }
>
> https://run.dlang.io/is/iem0PY
`shared struct Metadata` should make it work.
Turtles (shared) all the way down.
More information about the Digitalmars-d-learn
mailing list