当合约继承其他合约,仅一个单独的合约被区位链建立,代码从基础合约复制到建立的合约中。
pragma solidity ^0.4.16; contract owned { address owner; // 构造函数 function owned() { owner = msg.sender; } } // 继承合约owned的所有属性,但不能使用通过this进行外部访问 contract mortal is owned { function kill() { if (msg.sender == owner) selfdestruct(owner); } } // These abstract contracts are only provided to make the // interface known to the compiler. Note the function // without body. If a contract does not implement all // functions it can only be used as an interface. contract Config { function lookup(uint id) public returns (address adr); } contract NameReg { function register(bytes32 name) public; function unregister() public; } contract named is owned, mortal { function named(bytes32 name) { Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970); NameReg(config.lookup(1)).register(name); } function kill() public { if (msg.sender == owner) { Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970); NameReg(config.lookup(1)).unregister(); mortal.kill(); } } } contract PriceFeed is owned, mortal, named("GoldFeed") { function updateInfo(uint newInfo) public { if (msg.sender == owner) info = newInfo; } function get() public view returns(uint r) { return info; } uint info; } pragma solidity ^0.4.0; contract owned { address owner; function owned() public { owner = msg.sender; } } contract mortal is owned { function kill() public { if (msg.sender == owner) selfdestruct(owner); } } contract Base1 is mortal { function kill() public { /* do cleanup 1 */ mortal.kill(); } } contract Base2 is mortal { function kill() public { /* do cleanup 2 */ mortal.kill(); } } contract Final is Base1, Base2 { } pragma solidity ^0.4.0; contract owned { function owned() public { owner = msg.sender; } address owner; } contract mortal is owned { function kill() public { if (msg.sender == owner) selfdestruct(owner); } } contract Base1 is mortal { function kill() public { /* do cleanup 1 */ super.kill(); } } contract Base2 is mortal { function kill() public { /* do cleanup 2 */ super.kill(); } } contract Final is Base1, Base2 { } posted on 2018-02-28 17:29 北京涛子 阅读( ...) 评论( ...) 编辑 收藏转载于:https://www.cnblogs.com/liujitao79/p/8484797.html
相关资源:各显卡算力对照表!