无法在合同中声明bytes32固定数组或bytes32未固定数组?

时间:2019-02-01 13:31:52

标签: solidity

我试图在合同中声明bytes32数组,但这没有用。

 contract Demo{
        // compile error
        // TypeError: Type string memory[5] memory is not implicitly convertible 
        // to expected type bytes32[] storage ref.
        // bytes32[] public courseMap = ["Chinese", "English", "Math", "Computer", "Music"];
        // bytes32[5] courseMap = ["Chinese", "English", "Math", "Computer", "Music"];

        // compile error, the same as above
        bytes32[] public courseMap = ["Chinese", "English", "Math", "Computer", "Music"];
    }

1 个答案:

答案 0 :(得分:0)

您需要显式转换数组文字的第一个元素以指示类型。 Solidity编译器不够聪明,无法为您推断右侧类型:

bytes32[] public courseMap = [bytes32("Chinese"), "English", "Math", "Computer", "Music"];
相关问题