我试图在合同中声明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"];
}
答案 0 :(得分:0)
您需要显式转换数组文字的第一个元素以指示类型。 Solidity编译器不够聪明,无法为您推断右侧类型:
bytes32[] public courseMap = [bytes32("Chinese"), "English", "Math", "Computer", "Music"];