gpt4 book ai didi

stack - CompilerError : Stack too deep, 尝试删除局部变量

转载 作者:行者123 更新时间:2023-12-05 03:25:47 28 4
gpt4 key购买 nike

我正在尝试做一个 dapp 项目。

我有一个堆栈太深的错误,但我不知道如何解决这个问题。

CompilerError: Stack too deep, try removing local variables.--> contracts/proje.sol:145:5:|145 | function addRecord(address _addr, s ... gedOn, string memory ipfs) public {| ^ (Relevant source part starts here and spans across multiple lines).

而且实际上,struct 将包含比现在更多的数据。如果这样给出的数据个数有误,那么当我们要输入太多数据的时候怎么办?

contract Patient is Clinic {
uint256 public p_index = 0;

struct Records {
string cname;

string l_cadence;
string r_cadence;
string n_cadence;

string l_dsupport;
string r_dsupport;
string n_dsupport;

string l_footoff;
string r_footoff;
string n_footoff;

string l_steptime;
string r_steptime;
string n_steptime;


string admittedOn;
string dischargedOn;
string ipfs;
}

struct patient {
uint256 id;
string name;
string phone;
string gender;
string dob;
string bloodgroup;
string allergies;
Records[] records;
address addr;
}

address[] private patientList;
mapping(address => mapping(address=>bool)) isAuth;
mapping(address=>patient) patients;
mapping(address=>bool) isPatient;

function addRecord(address _addr, string memory cname, string memory l_cadence, string memory r_cadence, string memory n_cadence, string memory l_dsupport, string memory r_dsupport, string memory n_dsupport, string memory l_footoff, string memory r_footoff, string memory n_footoff, string memory l_steptime, string memory r_steptime, string memory n_steptime, string memory admittedOn, string memory dischargedOn, string memory ipfs) public {

}
}

最佳答案

编译器错误是关于 addRecord() 函数的参数数量。要解决这个问题,可以直接使用 Records struct 这样:

function addRecord(address _addr, Records memory record) public {
// your logic
}

解决这个问题的另一种选择是将类型函数从公共(public)更改为内部,例如:

function addRecord(address _addr, string memory cname, string memory l_cadence, string memory r_cadence, string memory n_cadence, string memory l_dsupport,
string memory r_dsupport, string memory n_dsupport, string memory l_footoff, string memory r_footoff, string memory n_footoff, string memory l_steptime,
string memory r_steptime, string memory n_steptime, string memory admittedOn, string memory dischargedOn, string memory ipfs) internal {
// your logic
}

注意:在进行此修改之前,请查看公共(public)类型函数和内部类型函数之间的区别 here .

关于stack - CompilerError : Stack too deep, 尝试删除局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71908632/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com