我继续获得Parseerror:预期类型名称//我想返回刚创建的结构时
我的坚固性是新手,我一直在尝试创建和获得结构而不将其添加到数组中。我一直在看到带有数组的结构和方法.push和我想尝试一下。
我已经与一个结构和一个功能创建了一个合同来创建和获取它。
如果我创建一个单个公共函数来创建但不返回,则它不会给我任何错误...如下:
struct Todo {
string name;
uint age;
}
function createTodo(string memory _name, uint _age) public pure{
Todo memory myTodo = Todo(_name, _age);
}
使用上述代码,我也想知道为什么它不会让我设置指针“ todo”作为存储,例如: todo storage mytodo = todo(_name,_age); 它给出了一个类型:todo内存并不是预期的结构存储指针的含义可转换。
接下来,我试图修改函数以创建和返回,但是当我开始获得ParseError时。
该代码如下:
function getTodo(string memory _name, uint _age) public returns(struct myTodo) {
Todo memory myTodo = Todo(_name, _age);
return myTodo;
}
使用AOBVE代码,我还尝试了“返回(struct),返回(struct Memory)”。...
我真的很感谢这里的任何类型的帮助。
非常感谢
I am new in Solidity and I have been trying to create and get STRUCT without adding it to an Array. I alway see Structs with arrays and the method .push and I wanted to try it without it.
I have created a single Contract with one Struct and one function to create and get it.
If I create a single public function to create, but not return, the struct it doesn´t give me any error... Like the following:
struct Todo {
string name;
uint age;
}
function createTodo(string memory _name, uint _age) public pure{
Todo memory myTodo = Todo(_name, _age);
}
With the above code I would also like to know why it wouldn´t let me set the pointer "Todo" as storage like: Todo storage myTodo = Todo(_name, _age); It gives an TypeError: Todo memory is not implicity convertible to expect type struct storage pointer.
Next, I tried to modify the function to create and RETURN but then is when I start getting the ParseError.
The code is the following:
function getTodo(string memory _name, uint _age) public returns(struct myTodo) {
Todo memory myTodo = Todo(_name, _age);
return myTodo;
}
With the aobve code I also tried in "returns(struct), returns(struct memory)"....
I would really appreciate any type of help here.
Thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您收到此错误,因为您错误地在
getTodo()
函数上设置返回关键字。在您的情况下,您必须以这种方式更改功能:如果要处理存储结构,请参阅此智能合约代码:
You received this error because you're wrong to set a returns keyword on
getTodo()
function. In your case, you must change your function in this way:If you want to handle storage structs, see this smart contract code: