solidity中super关键字

pragma solidity ^0.4.5;

contract C {
     uint u;
     function f() {
       u = 1;
     }
}

contract B is C {
     function f() {
       u = 2;
     }
}

contract A is B {
     function f() {  // will set u to 3
       u = 3;
     }
     function f1() { // will set u to 2
       //当使用super时,调用的是继承的该函数,不是它自己,比如下边给出的例子中,函数名字是相同的,要知道调用的不是它自己,是继承父合约中的同名函数。
       super.f();
     }
     function f2() { // will set u to 2
       B.f();
     }
     function f3() { // will set u to 1
       C.f();
     }
}
contract RefundablePostDeliveryCrowdsale is RefundableCrowdsale, PostDeliveryCrowdsale {
    function withdrawTokens(address beneficiary) public {
        require(finalized());
        require(goalReached());
        //super关键字,此时withdrawTokens调用的是PostDeliveryCrowdsale内的
        super.withdrawTokens(beneficiary);
    }
}

你可能感兴趣的:(区块链,solidity)