我试图在契约中声明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"];
}发布于 2019-02-02 01:05:10
您需要显式转换数组文字的第一个元素来指示类型。Solidity编译器不够智能,无法为您推断右侧类型:
bytes32[] public courseMap = [bytes32("Chinese"), "English", "Math", "Computer", "Music"];https://stackoverflow.com/questions/54480589
复制相似问题