基于以太坊的智能合約開發教程Solidity mapping在結構體當中的使用
pragma solidity ^0.4.0;
contract mappingTest{
struct Student {
uint grade;
string name;
mapping (uint => string) map;
}
// 默認為storage型別,只能夠用storage型別來操作我們的結構體中的mapping型別
Student s;
// memory的物件不能夠直接的操作struct結構體當中的mapping
function test()public view returns(uint,string,string){
// 在初始化結構體的時候,會忽略這樣的mapping型別
Student memory stu = Student(99,"zhangsan");
//把記憶體當中的stu物件復制給s這樣的storage物件,只能通過storage物件來操作結構體中的mapping物件
s = stu;
s.map[0] = "helloworld";
return (s.grade,s.name,s.map[0]); // 99,zhangsan,helloworld
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/374895.html
標籤:區塊鏈
上一篇:區塊鏈的幾點理解
下一篇:第十章新技術
