pragma solidity ^0.4.0;
contract structTests{
//结构体定义
struct Student{
uint grade;
string name;
mapping(uint => string) map;//很特殊的类型,不会报错
}
Student mm;//默认为storage类型,只能用storage类型的操作来操作结构体中的mapping类型
//结构体初始化第一种方式
function inIt1() public returns(uint,string){
//在函数体内部的struct默认的是strorage的类型
Student memory s = Student(100,"chenshimei");
mm = s;
mm.map[0] = "chenshimei9191";
return(s.grade,s.name);
}
}
52.Solidity-Struct_2_mapping
最新推荐文章于 2025-01-21 10:47:12 发布
该文章介绍了如何在Solidity编程中定义和初始化struct,特别是处理mapping类型的字段。通过一个名为Student的struct示例,展示了如何声明、赋值以及操作存储在合约中的struct变量。文章还提到了在函数内部struct的默认类型是memory,而合约变量默认为storage类型。
9919

被折叠的 条评论
为什么被折叠?



