0

noob solidity question… if I have a struct that looks like this:

struct Special {
    string name;
    address[] deals;
    mapping (address => string[5]) dealNames;
}

how can I initialize a new "Special" with an empty deals array and empty dealNames mapping, having only a string for name.

I've tried this and it errors out (obviously?)

Special special = Special({
    name: "bingo",
    deals: [],
    dealNames: {}
});
1

You can initialise the Struct like this:


address[] memory addresses;
Special memory s = Special("Test", addresses);

There a section in the FAQ of the Solidity documentation that you might also find useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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