通过继承构造函数

constructor through inheritance

所以我正在尝试一个使用带有继承的构造函数的示例,但是混音 ide 返回错误,而我正在学习的课程并非如此。任何 idea 可能导致错误的原因,或者是否有更新的 solidity 版本的更新?

pragma solidity ^0.8.0;

contract myConstruct {
    string public name;

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

contract mySecondConstruct is myConstruct {
    constructor (string memory _name) myConstruct(_name) {} ;
}

分号 ; 不属于该块之后。 (你的情况是空块 {}

正确的语法:

// remove the semicolon
constructor (string memory _name) myConstruct(_name) {}