31-Solidity8.0-运行父级合约构造函数

273 阅读1分钟

下面是两种输入构造函数参数的方法

构造函数运行的顺序按照继承的顺序运行

image.png

源码:

pragma solidity ^0.8.7;

contract S {
    string public name;

    constructor(string memory _name) {
        name = _name;
    }
}

contract T {
    string public text;

    constructor(string memory _text) {
        text = _text;
    }
}

contract U is S("s"), T("t") {

}

contract V is S, T {
    constructor(string memory _name, string memory _text) S(_name) T(_text) {

    }
}

contract VV is S("s"), T {
    constructor(string memory _text) T(_text) {

    }
}