2

For expl.

mapping(uint => Test) tests;

struct Test {
    uint id;
    mapping(address => uint) votes;
}
function newTest() public {
    test[0] = Test(0, <EMPTY_MAPPING>)
}
jasper
  • 689
  • 6
  • 21

1 Answers1

4

You can rewrite your code like this:

tests[0] = Test({
  id: 0
});

Solidity will make votes an empty mapping by default. Btw, there's also a typo in your code: should be tests[0] instead of test[0].

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143
  • Wrote that in Stackexchange instead of int he IDE. Thanks Paul that'll do it, I could not find the question you asked earlier. – jasper Nov 21 '18 at 13:19
  • This no longer works in newer versions of solidity, this is how it should be done now: Test storage test = tests[0]; test.id = 0; – Adham Mar 12 '23 at 21:59