0

Why is remix telling me "expected primary expression" when I declare my modifier?

contract Autos {

// <-------- EXTENDED CONSTRUCTOR FOR TEST PURPOSES ----------->

constructor() public {

address owner;
owner = msg.sender;


bool ifmember;
mapping(address => bool) members;

modifier onlyMember {
    require(msg.sender == owner || members[msg.sender] == true);
    _;
    }


function addMember(address _address) public onlyMember {
    ifmember = members[_address];
    }



}

// <--------------------- END CONSTRUCTOR --------------------->

When I create a new SOL with just the following, I get no error:

pragma solidity ^0.4.24;

contract Autos {

address public owner;
mapping(address => bool) members;


modifier onlyMember {
    require(msg.sender == owner || members[msg.sender] == true);
    _;
    }


}
1

You don't declare functions or modifiers within the constructor. It should be something like this:

contract Autos {
    address owner; 

    bool ifmember;
    mapping(address => bool) members;

    constructor() public {
        owner = msg.sender;
    }

    modifier onlyMember {
        require(msg.sender == owner || members[msg.sender] == true);
        _;
    }
    function addMember(address _address) public onlyMember {
        ifmember = members[_address];
    }
}
|improve this answer|||||

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.