solidity学习笔记(一)

枚举类型测试

pragma solidity ^0.4.16;
/**
 * The enumtt contract does that 枚举类测试
  错误说明: 语言里函数需要限制两次:
  1.是对于所有函数都需要有的限制 可见性visibility(有public等);
  2.是对于有返回值类型的函数必须有的限制 
    变动性multability(view:无constant; pure:constant变量 )
  3.构造函数在这种语言里是不能有其他类型的,只能是empty(void)
    即后面没有returns语句。
 */
contract enumtt {
    event e(uint _a);
    enum GoAction { GoLeft, GoRight, GoStraight }
    GoAction ga;
    GoAction constant defaultAction  = GoAction.GoStraight;

    function setGoRight () public {
        ga = GoAction.GoRight;      
    }
    function getGoAction () public view returns (GoAction){
        return ga;
    }

    function getDefaultAction() public pure returns (uint){
        return uint(defaultAction);
    }


    function enumtt () public {
        e(uint(defaultAction));         
    }   
}

猜你喜欢

转载自blog.csdn.net/qq_33828894/article/details/81271992