0

So I've updated solidity to version 0.5.0 and I'm trying to re-write my code. One thing that worked before was comparing contract (represented by its address) to addresses. So now I'm getting the following error:

TypeError: Operator == not compatible with types contract User and address payable 

Then I've tried to just add the address field, but the compiler won't allow it. For instance, the following won't compile because it expects ; instead of . :

address a = User.address; 

So how do I solve this problem of getting the address field from a contract so the compiler lets me compare those two? Here is the part of the code that won't compile because of that require statement:

mapping(address=>User) public users; function register(string memory _nome) public { require(users[msg.sender]==0x0000000000000000000000000000000000000000); users[msg.sender] = new User(_nome,msg.sender); } 

1 Answer 1

1

I assume by "that if statement" you mean the require?

Just use an explicit cast to address:

require(address(users[msg.sender]) == 0x0000000000000000000000000000000000000000); 
2
  • yes, I'll correct it Commented Jan 9, 2019 at 7:42
  • that works, thanks. I've assumed casting was not yet implemented in solidity so I didn't bother trying. Commented Jan 9, 2019 at 8:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.