Ethereum 坚固的结构

Ethereum 坚固的结构,ethereum,solidity,smartcontracts,Ethereum,Solidity,Smartcontracts,我学会了坚固 在struct一章中,我尝试了这段代码,当我想返回标题时,我得到了book_id ok,并且我更改了uint 要在代码中输入字符串,请告诉我错误 pragma solidity ^0.5.0; contract test { struct Book { string title; string author; uint book_id; } Book book; function setBook() public

我学会了坚固 在struct一章中,我尝试了这段代码,当我想返回标题时,我得到了book_id ok,并且我更改了uint 要在代码中输入字符串,请告诉我错误


pragma solidity ^0.5.0;

contract test {
   struct Book { 
      string title;
      string author;
      uint book_id;
   }
   Book book;

   function setBook() public {
      book = Book('Learn Java', 'TP', 1);
   }
   function getBookId() public view returns (uint) {
      return book.book_id;
   }
}


如何解决此问题?

当您使用引用类型(例如
string
)时,需要指定它们的位置。资料来源:

对于函数返回值,唯一有意义的位置是内存

在数据类型之后指定位置,因此在本例中
返回(字符串内存)


谢谢PetrHejda
function getBookTitle() public view returns (string memory) {
    return book.title;
}