1

I'm new to solidity, I'm writing a smart contract for ballot process but getting the error in my ballot function in the line proposals = proposals.slice(0, _numProposals);. I've traversed all the relevant questions to it but finally concluded to ask you people when my problem seemed different from others.

pragma solidity ^0.8.10; contract Ballot { struct Voter { uint weight; bool voted; uint8 vote; } struct Proposal { uint voteCount; } enum Stage {Init, Reg, Vote, Count} Stage public stage = Stage.Init; address chairperson; mapping(address => Voter) voters; Proposal[] proposals; uint startTime; /// Create a new ballot with $(_numProposals) different proposals. function ballot(uint8 _numProposals) public { chairperson = msg.sender; voters[chairperson].weight = 2; proposals = proposals.slice(0, _numProposals); stage = Stage.Reg; startTime = block.timestamp; } 

I'm getting the same error after I've also added proposals = proposals.slice[0 : _numProposals];. Please explain to me in detail what is the root cause?

Thanks in advance.

0

1 Answer 1

1

According to the documentation here

As of now, array slices are only implemented for calldata arrays.

Your proposals array is stored in the storage and it is not calldata. check these for more information about the difference between storage , memory, and calldata

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.