1

I have 2 structs like this:

struct A { ... }
struct B { A a; }

A[] aa;
B[] bb;

function createB(uint256 aIndex) {
  A storage a = aa[aIndex];
  B memory b = B({a: a});

  bb.push(b);
}

Instances of A stored in array and in

I have couple of questions about it:

  1. Why doesn't works explicit declaration of a inside B as storage, i.e. A storage a doesn't compile?
  2. Am I right that anyway I'll have b.a as storage ref, not as copy of original A instance?

1 Answer 1

0

1) Sorry, but why do you need explicit declaration of a as storage? Why not use:

function createB(uint256 aIndex) {
  B memory b = B({a: aa[aIndex]});

  bb.push(b);
}

2) No. Either way you will store copy.

2
  • Because I have 2 arrays of different structs and want to be able to refers from one to another without copying.
    – Alex G.P.
    Apr 10, 2018 at 4:05
  • It is sad that one storage struct unable to keep storage reference to another, just tested it. Thanks.
    – Alex G.P.
    Apr 10, 2018 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.