Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ethereum 为什么要将存在的solidity合同实例作为参数传递给合同构造函数_Ethereum_Smartcontracts - Fatal编程技术网

Ethereum 为什么要将存在的solidity合同实例作为参数传递给合同构造函数

Ethereum 为什么要将存在的solidity合同实例作为参数传递给合同构造函数,ethereum,smartcontracts,Ethereum,Smartcontracts,有关以下代码段,请参见 为什么这一行(将constact实例传递给构造函数)起作用计数器(_计数器[msg.sender])。增量(msg.sender) 我在使用混音IDE contract CounterFactory { mapping(address => Counter) _counters; function createCounter() public { require (_counters[msg.sender] == Counter

有关以下代码段,请参见

为什么这一行(将constact实例传递给构造函数)起作用<代码>计数器(_计数器[msg.sender])。增量(msg.sender)

我在使用混音IDE

contract CounterFactory {
 
    mapping(address => Counter) _counters;

    function createCounter() public {
        require (_counters[msg.sender] == Counter(0));
        _counters[msg.sender] = new Counter(msg.sender);
    }
    
    function increment() public {
        require (_counters[msg.sender] != Counter(0));
        Counter(_counters[msg.sender]).increment(msg.sender);
        // The following line also works as usual.
        // _counters[msg.sender].increment(msg.sender);
    }
    
    function getCount(address account) public view returns (uint256) {
        require (_counters[account] != Counter(0));
        return (_counters[account].getCount());
    }
    
    function getMyCount() public view returns (uint256) {
        return (getCount(msg.sender));
    }
 
}