问题将值推送到结构中的枚举数组
Problem push values to an enum array in a struct
我正在尝试将值推送到存储在结构中的枚举数组,但我无法推送值。我哪里错了?这是我的代码:
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.12;
contract Test {
address private owner; // owner is Insurance Company
mapping (address => Record) records;
enum Animal {Lion, Tiger, Zebra}
struct Record {
Animal[] animal; // status of the record
}
constructor() { // set owner on deploy as deployer address
owner = msg.sender;
}
function addRecord() public {
Record storage record = records[msg.sender];
record.animal.push(0);
// record.animal[0] = Lion;
// record.animal = [Lion, Tiger};
}
}
我的错误:
TypeError: Member "push" not found or not visible after argument-dependent lookup in enum Test.Animal[] storage ref.
--> b.sol:21:9:
|
21 | record.animal.push(0);
| ^^^^^^^^^^^^^^^^^^
试试这个:
record.animal.push(Animal.Lion);
我正在尝试将值推送到存储在结构中的枚举数组,但我无法推送值。我哪里错了?这是我的代码:
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.12;
contract Test {
address private owner; // owner is Insurance Company
mapping (address => Record) records;
enum Animal {Lion, Tiger, Zebra}
struct Record {
Animal[] animal; // status of the record
}
constructor() { // set owner on deploy as deployer address
owner = msg.sender;
}
function addRecord() public {
Record storage record = records[msg.sender];
record.animal.push(0);
// record.animal[0] = Lion;
// record.animal = [Lion, Tiger};
}
}
我的错误:
TypeError: Member "push" not found or not visible after argument-dependent lookup in enum Test.Animal[] storage ref.
--> b.sol:21:9:
|
21 | record.animal.push(0);
| ^^^^^^^^^^^^^^^^^^
试试这个:
record.animal.push(Animal.Lion);