如何在0.5.0 solidity编译器版本中返回字符串?
合同测试{ string public text =‘show me’; function test()public view returns(string){ 返回文字; }}我有 …
//The version I have used is 0.5.2 pragma solidity ^0.5.2; contract Inbox{ string public message; //**Constructor** must be defined using ��constructor�� keyword //**In version 0.5.0 or above** it is **mandatory to use ��memory�� keyword** so as to //**explicitly mention the data location** //you are free to remove the keyword and try for yourself constructor (string memory initialMessage) public{ message=initialMessage; } function setMessage(string memory newMessage)public{ message=newMessage; } function getMessage()public view returns(string memory){ return message; }}
只需要添加 memory 后 string , 像这样:
memory
string
function test() public view returns (string memory) {
另一个变化: https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html#interoperability