有人可以给出坚固的界面工作实例吗?

时间:2018-02-04 20:25:33

标签: solidity

我收到错误"此合同未实现所有功能,因此无法创建。"虽然使用界面坚固可以有人帮我这个或者请给我一个坚实的界面工作实例?

pragma solidity ^0.4.0;

interface Audit {
    function CheckBlance() public returns(bool);
    function lending() public returns(bool);
}

contract Fin_Inst is Audit{
    uint public Money;

    function Fin_Inst(uint Value) public {
        Money = Value;
    }

    function Deposit(uint DepAmount) public{
        Money = Money + DepAmount; 
    }

    function Withdraw(uint WithdAmount) public{
        if(CheckBlance(WithdAmount) == true){
            Money = Money - WithdAmount;
        }

    }

    function Balance() public constant returns (uint){
        return Money;
    }

    function CheckBlance(uint WithdAmount) public returns (bool){
        return Money >= WithdAmount;
    }

    function lending() public returns (bool){
        return Money > 0;
    }

}

2 个答案:

答案 0 :(得分:1)

我做了一些小改动,现在当你运行Create Fin_Inst时,它执行时没有任何错误消息。

似乎错误出现在接口方法CheckBalance(uint WithdAmount)中的函数参数中。

以下是已修改代码

pragma solidity ^0.4.19;

interface Audit {
    function CheckBalance(uint WithdAmount) public view returns(bool);
    function lending() public view returns(bool);
}

contract Fin_Inst is Audit{
    uint public Money;

    function Fin_Inst(uint Value) public {
        Money = Value;
    }

    function Deposit(uint DepAmount) public {
        Money = Money + DepAmount; 
    }

    function Withdraw(uint WithdAmount) public {
        if(CheckBalance(WithdAmount) == true){
            Money = Money - WithdAmount;
        }
    }

    function Balance() external view returns (uint) {
        return Money;
    }

    function CheckBalance(uint WithdAmount) public view returns (bool) {
        return Money >= WithdAmount;
    }

    function lending() public view returns (bool) {
        return Money > 0;
    }
}

答案 1 :(得分:0)

是的,为了实现一个方法,你必须完全尊重签名(同名和参数)。

例如,您可以在合同3中使用不同的方法 method1()method1(unit x)method1(unit[] xs)

要实现此接口,您必须在子契约中编写3个方法。因此,如果您只实施method1(),则他们仍处于待审状态method1(unit x)method1(unit[] xs)

这称为Function overloading。因此CheckBalance(uint WithdAmount)CheckBalance()

不同