1
struct Petition {
    uint id;
    string name;
    string description;
    uint voteFor;
    uint voteAgainst;
    address[] addressOfVotedForUsers;
    address[] addressOfVotedAgainstUsers;
    mapping(address=>bool) usersVotedFor;
    mapping(address=>bool) usersVotedAgainst;
}

function addPetition(string memory _name, string memory _desc) public {
    petitions[petitionCount] = Petition(petitionCount,_name,_desc,0,0); 
    petitionCount++; 
}

s/VoteCast.sol:42:34: TypeError: Wrong argument count for struct constructor: 5 arguments given but expected 7. Members that have to be skipped in memory: usersVotedAgainst usersVotedFor
  petitions[petitionCount] = Petition(petitionCount,_name,_desc,0,0);

I have a struct where I don't want the value of the address[] arrays to be intialised. But I get a error expected 7 arguments, instead got 5. Is there any work around for this?

2
  • 2
    There is nothing in this code that could possibly give this error!!! Apr 4 '19 at 14:37
  • Please add the code segment where you are trying to initialize this and getting error(s).
    – sp4c3
    Apr 4 '19 at 14:41
1

struct Petition {
    uint id;
    string name;
    string description;
    uint voteFor;
    uint voteAgainst;
    address[] addressOfVotedForUsers;
    address[] addressOfVotedAgainstUsers;
    mapping(address=>bool) usersVotedFor;
    mapping(address=>bool) usersVotedAgainst;
}

mapping(uint => Petition) public petitions;
uint petitionCount=0;

function addPetition(string memory _name, string memory _desc) public {
    address[] memory whatever;  //empty array
    petitions[petitionCount] = Petition(petitionCount, _name, _desc, 0, 0, whatever, whatever); 
    petitionCount++; 
}

function addPetition(string memory _name, string memory _desc, address[] memory x, address[] memory y) public {
    petitions[petitionCount] = Petition(petitionCount, _name, _desc, 0, 0, x, y); 
    petitionCount++; 
}

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.