ethereum(以太坊)(基础)--容易忽略的坑(一)

pragma solidity ^0.4.0;

contract base{
    address public _owner=msg.sender;
    uint _a;
    string internal _b ;
    uint private _c;
    //uint external _d;ParserError: Expected identifier but got ‘external‘

    function base() {
        _a =10;
        //uint  _d public;Expected ‘;‘ but got ‘public‘
        string _f;
    }

    function getA() public view returns (uint){
        return _a;
    }

    function setA(uint c) internal{
        _a=c;
    }

    //modifier OnlyAdmin() private{Expected ‘{‘ but got ‘private‘
    modifier OnlyAdmin(){
        require(_owner == msg.sender);
        _;
    }

    function kill() OnlyAdmin() external{
        setA(6);
        this.getA();
        selfdestruct(msg.sender);
    }
}
contract base1 is base{
    function getA() public view returns(uint){
        //return _c;DeclarationError: Undeclared identifier. Did you mean "_a" or "_b"?
        //return _b;Overriding function return types differ:覆盖函数返回类型不同
        return _a;
    }
    function getE(){
        this.kill();
        this.getA();
        //this.setA(20);Member "setA" not found or not visible after argument-dependent lookup in contract base1
    }
}

contract base2{

    uint public _e;
    function getE(){
        //this.getA();Member "getA" not found or not visible after argument-dependent lookup in contract base2
    }
}
//contract base2 is base1,base{ Linearization of inheritance graph impossible:继承图的线性化是不可能的
contract base3 is base,base1{
    uint public _e;
}

原文地址:https://www.cnblogs.com/eilinge/p/10074210.html

时间: 2024-10-09 05:31:14

ethereum(以太坊)(基础)--容易忽略的坑(一)的相关文章

ethereum(以太坊)(基础)--容易忽略的坑(二)

pragma solidity ^0.4.0; contract EMath{ string public _a="lin"; function f() public{ modify(_a); } //function modify(string storage name) private{ function modify(string memory name) private{ //string storage c = name;Type string memory is not i

以太坊基础福运来平台制作

控制和责任像以太坊福运来平台制作请添加链接描述Q_1151880099这样的开放区块链是安全的,因为它们是去中心化的.这意味着以太坊的每个用户都应该控制自己的密钥,这些密钥可以控制对资金和合约的访问.一些用户选择通过使用第三方保管人(比如交易所钱包)放弃对密钥的控制权.在本书中,我们将教你如何控制和管理你自己的密钥. 这种控制带来了很大的责任.如果你丢失了你的钥匙,你将无法获得资金和合约.没有人可以帮助你重新获得访问权 - 你的资金将永远锁定.以下是一些帮助你管理这一责任的提示: 提示你选择密码

区块链:以太坊基础之安装Geth

1.安装cmake 智能合约需要cmake3.x版本才可以编译 # 下载包 wget https://cmake.org/files/v3.3/cmake-3.3.2.tar.gz # 解压 tar zxvf cmake-3.3.2.tar.gz cd cmake-3.3.2 # 安装 ./configure make make install # 编辑环境变量配置文件 vim /etc/profile # 在末尾加上 export PATH=/usr/cmake/cmake-3.3.2/bin

ethereum(以太坊)(五)--Bool

pragma solidity ^0.4.0; contract Bool{ uint num1 = 100; uint num2 = 200; bool _c = true; // && == function yuf() constant returns(bool){ return num1 == num2 && _c; //false } // || != function huof() constant returns(bool){ return num1 != n

ethereum(以太坊)(六)--整型(int)

/* uint8 uint16 ...uint256 int8 int16 int24 ..int256 uint => uint256 int => int256 int8 有符号 +1 ,-3 uint 无符号 1,2 int8 8(位) 1 111 1111 ~ 0 111 1111 - (1+2+4+8+16+32+64) ~ + (1+2+4+8+16+32+64) -127 ~ 127 255(127*2+0) uint8 0000 0000 ~ 1111 1111 (0~255)

ethereum(以太坊)(九)--global(全局函数)

pragma solidity ^0.4.0; contract modifierTest{ bytes32 public blockhash; address public coinbase; uint public difficulty; uint public gaslimit; uint public blockNum; uint public timestamp; bytes public calldata1; uint public gas; address public sende

ethereum(以太坊)(十)--字节数组

pragma solidity ^0.4.0; contract byte1{ /* 固定大小字节数组(Fixed-size byte arrays) 固定大小字节数组可以通过bytes1,bytes2...bytes32声明,byte=byte1 bytes1 只能存储1个字节,也就是二进制的8位内容 //一个字节=8位2进制/一个字母/符号/(1/3汉字) bytes2 只能存储2个字节,也就是二进制的8*2位内容 bytes32 只能存储32个字节,也就是二进制的8*32=256位内容 十

ethereum(以太坊)(十四)--Delete

pragma solidity ^0.4.10; contract Delete{ /* delete可用于任何变量(除mapping),将其设置成默认值 bytes/string:删除所有元素,其长度变为0 bytes32:重置所有索引的值 mapping:什么都不会发生 mapping(key=>value)中的key:删除与该键相关的值 */ string public str1 ='nihao'; function deletstr() public{ delete str1; } fu

区块链:以太坊基础之搭建私链

1.新建genesis.json {  "config": {    "chainId": 666,    "homesteadBlock": 0,    "eip150Block": 0,    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",    "eip