0

In the below code I can successfully deploy the "UserRegistry" contract, but when I try to deploy the "User" contract, I get the error This contract does not implement all functions and thus cannot be created. Based on this example, I thought I could inherit modifiers from a contract containing only modifiers. I am not seeing why I can compile this Reddit user's code but not mine as it seems to fit the same pattern.

    pragma solidity ^0.4.19;
contract UserRegistry {

    address owner;

    struct user {
        uint dateAdded;
        uint repuation;
    }

    mapping(address => user) users;

    modifier IsUser(address account) {
        require(
            users[account].dateAdded != 0   
        );
        _;
    }

    modifier OwnerApproved() {
        require(
            msg.sender == owner
        );
        _;
    }

     constructor(address _owner) public {
        owner = _owner;
    }
}

contract User is UserRegistry {

    event EventAddUser(address account);

    function addUser(address account) public {
        users[account].dateAdded = now;

        emit EventAddUser(account);
    }

    function updateUserRep(address _user) public IsUser(_user) OwnerApproved {
        users[_user].repuation +=  1;
    }

}

1 Answer 1

0

Your User class is not implementing the constructor. You can call the parent constructor in this way

constructor(address _owner) UserRegistry(_owner) public { }

please note that also the addUser is actually wrong. You need to create the struct

users[account] = user(now, 0);
2
  • So, does this mean that my contract UserRegistry actually has a separate users mapping from the one in the "Users" contract? By this I mean, if I were to put the "addUser" function in the "UserRegistry" contract in addition to the "Users" contract, that calling users[address] in "Users" would not be the same as calling ` users[address]` in UserRegistry?
    – Min
    May 9, 2018 at 5:36
  • depends where the users is defined. if you have the same function in UserRegistry but you call it from Users contract then the latter will be executed. In solidity all functions are virtual by default, so the most derived one would be call unless you provide the contract name. The fields follow the same 'rule' so if you have another users mapping inside User contract it would be different than the one inside UserRegistry solidity.readthedocs.io/en/v0.4.21/contracts.html#inheritance
    – qbsp
    May 9, 2018 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.