基于以太坊的智能合约开发教程Solidity 构造函数
pragma solidity ^0.4.0;
contract constructTest{
// 在合约部署时,构造函数就会执行
uint public a;
// 旧版本创建构造函数要与合约名相同
function constructTest(){
a = 100;
}
}
contract constructTest1{
uint public a = 999;
// 新版本创建构造函数使用constructor关键字
// constructor(){
// a =111;
// }
constructor(uint _a, uint b){
a = _a;
}
}
contract constructTest2{
address public owner;
constructor(){
owner = msg.sender;
}
}