current position:Home>How to determine whether a key exists in a mapping? Struct is defined in the library (in solidity).

How to determine whether a key exists in a mapping? Struct is defined in the library (in solidity).

2022-02-03 20:47:26 Q & A of Denglian community

pragma solidity ^0.4.8;library Library {  struct data {     unit val;   }}

-

contract Array{    using Library for Library.data;    mapping(address => Library.data) clusterContract;    function addCluster(address id) returns(bool){        if(clusterContract[id] == address(0) ){ //error occurs!            clusterContract[id] = list;            return true;        }        return false;     }}

Judgment statement if(clusterContract[id] == address(0)) Gave an error . The mistakes are as follows :

Operator == not compatible with types struct Library.data storage ref and addressE               if(clusterContract[id] == address(0) ){...

Excuse me, : How can I solve this mistake ?

Thank you for your valuable time and help .




copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032047233756.html

Random recommended