Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Differences between these 2 functions in solidity?

I don’t get the difference between these 2 functions in solidity, will the same result be returned?

address oldVoter;

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


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


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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this function is modified with checkSender modifier:

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

since it is modified you can see this function like this:

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

There is another function with the same name changeVote, but if you notice it does not have any modifier and does not take any argument. It is absolutely legal to have the same function name with a different number of parameters of different data types for incoming parameters.

You can have multiple definitions for the same function name in the same scope in Solidity. This is called function overloading. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. Return types are not taken into consideration for determining valid function signatures.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading