2017-08-04 82 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?