I want to know how to initialize the structure created using 'struct' key word.
I can't see use of 'new' key word in Solidity documentation.
Some body please guide me.
Zulfi.
Like this:
struct Example {
uint a;
uint b;
uint c;
}
Example public example;
function set1(uint _a, uint _b, uint _c) public {
example.a = _a;
example.b = _b;
example.c = _c;
}
function set2(uint _a, uint _b, uint _c) public {
example = Example(_a, _b, _c);
}
function set3(uint _a, uint _b, uint _c) public {
example = Example({a: _a, b: _b, c: _c});
}
new
keyword is used for instantiating a new contract, for example: MyContract myContract = new MyContract(1, 2, 3);
. In other words, it is used for deploying a contract on-chain (i.e., from another contract) instead of off-chain (e.g., from a web3-based NodeJS script).
Commented
Mar 11, 2020 at 5:17