2017-08-04 84 views
2

对不起,如果它是重复的问题。 “_”运算符做了什么?以太坊合同_的运营商;

此代码是从复仇合同手册: https://ethereum.org/token#deploying

contract owned { 
    address public owner; 

    function owned() { 
     owner = msg.sender; 
    } 

    modifier onlyOwner { 
     if (msg.sender != owner) throw; 
     _; 
    } 

    function transferOwnership(address newOwner) onlyOwner { 
     owner = newOwner; 
    } 
} 
+1

你的问题在这个其他网站解决。 https://ethereum.stackexchange.com/questions/5861/are-underscores-in-modifiers-code-or-are-they-just-meant-to-look-cool?newreg=95181540ee304308aa071f6a2b97d87f – Dez

回答

0

它内部改性剂使用。

“函数体被插入修改器的 定义中的特殊符号”_“出现的位置。

参考: Contracts — Solidity 0.4.19 documentation

而如果它是在一个修改器只能使用一次,你可以把它看成如下: 返回变量分配后,_返回控制流的是什么在当前修饰符旁边(当前修饰符旁边可以是下一个修饰符或函数)。

你可以看到在答案的详细解释和例子: Are underscores _ in modifiers code or are they just meant to look cool?