这两个功能在可靠性方面的区别?

Differences between these 2 functions in solidity?

我不明白这两个函数在 solidity 中的区别,会返回相同的结果吗?

address oldVoter;

  modifier checkSender(address actualVoter) {
        require(oldVoter != actualVoter);  
        _; 
    }


    function changeVote(address caller)public  {
        oldVoter =  caller;
    }


    function changeVote() public checkSender(msg.sender){
        olderVoter = caller;
    }

你没有从你的函数中返回任何东西。 changeVote(address caller)(第一个)将 oldVoter 设置为 caller 输入。第二个不应编译,因为 caller 未在其中定义。

此函数用checkSender修饰符修饰:

 function changeVote() public checkSender(msg.sender){
        olderVoter = caller;
    }

修改后你可以看到这个函数:

function changeVote() public checkSender(msg.sender){
        require(oldVoter != actualVoter); 
        // "_" in modifier is placeholder. saying that place the modified function here
        olderVoter = caller;
    }

还有另一个同名函数 changeVote,但如果您注意到它没有任何修饰符并且不接受任何参数。传入参数不同数据类型不同参数个数相同的函数名是绝对合法的

您可以在 Solidity 的同一范围内为同一函数名称定义多个。这叫做function overloading。函数的定义必须在类型上彼此不同 and/or 参数列表中参数的数量。 Return 确定有效函数签名时不考虑类型。