Arrays
將結構推入數組
我正在嘗試做的是基本的,將結構添加到儲存陣列。但由於某種原因,我收到以下錯誤
TypeError: Indexed expression has to be a type, mapping or array (is function (struct KYC.Fraud storage ref) returns (uint256))
contract KYC { struct Fraud { address bank; bytes32 accountNumber; bytes32 routingNumber; uint256 amount; uint256 timestamp; } Fraud[] frauds; function reportFraud (address bank, bytes32 accountNumber, bytes32 routingNumber, uint256 amount) external returns(uint256 fraudID) { Fraud memory fraud = Fraud(bank, accountNumber, routingNumber, amount, now); frauds.push[fraud]; return frauds.length - 1; }
push
是一個函式。您正在使用括號,就好像它是一個數組,您可以在其中查找結構的索引,這就是導致錯誤的原因。只需更改push[fraud]
為push(fraud)
.