嗨,我有这个代码,错误是:

UnimplementedFeatureError: Copying of type struct spu_university.all_courses memory[] memory to storage not yet supported.

我怎么才能解决这个问题??

//SPDX-许可证-标识:MIT 现实性=0.4.22<0.9.0;

合同SPU_COUNTY{

address  is_admin;
constructor(){
    is_admin = msg.sender;
}

modifier onlyAdmin(address x) {
    require(x== is_admin, "Permission Denied. You do not have admin access.");
    _;  }

uint s_counter=0;

struct students_marks{
    uint id;
    uint mark;
}

struct  all_courses{

    string course_name ;
    uint mark ;
}

struct warning {

    string date ;
    string description;
}

struct  course {
    string name ;
    uint id;
    uint weekly_hours;
    uint level ;

    
    students_marks[] marks;
    }

    struct prof {
    
    uint id ;
    string firstName;
    string lastName;
    string fatherName;
    string motherName;
    string gender;
    string email;
    string collegeName;
    string dateOfBirth;
    string mobileNumber; 
    string specialization ;


}

struct  student  {

    uint  id ;
    string firstName;
    string lastName;
    string fatherName;
    string motherName;
    string gender;
    string email;
    string collegeName;
    string dateOfBirth;
    string mobileNumber;
    
    all_courses[] course;
    
    warning[] s_warnings;
    
    }

student[] studentList ;
prof[] profList;
course[] courselist; 

mapping(uint => student) public getstudent;
mapping(uint => prof) public getprof;   
mapping(uint => course) public getcours; 

//-注册函数-----

function registerStudent(
    uint  _id,
    string memory _firstName,
    string memory _lastName,
    string memory _fatherName,
    string memory _motherName,
    string memory _gender,
    string memory _email,
    string memory _collegeName,
    string memory _dateOfBirth,
    string memory _mobileNumber

    ) onlyAdmin(msg.sender) public {

    
          student memory x= student(_id,_firstName,
          _lastName,_fatherName,_motherName,_gender,
          _email,_collegeName,_dateOfBirth,
          _mobileNumber,
          new all_courses[] (0),
          new warning[] (0) );
          
          studentList.push(x);

    getstudent[_id]=studentList[s_counter];
    s_counter ++;
    
}

}

我试了很多方法都不管用.

推荐答案

您的存储内存与此处不匹配.我不会详细讨论存储和内存是什么,你可以在这里阅读到here.

此外,您还可以找到与您的问题类似的其他堆栈溢出帖子,这些帖子解释了为什么会出现此特定错误,例如,请参见herehere.

但是,我将给您一些关于如何重构代码的起点,这样您就不会再次遇到同样的错误.看看下面从您的示例中派生出来的更简化的示例.

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;


contract spu_university {
    constructor(){
    }

    uint s_counter=0;

    struct course {
        string name;
    }

    struct student {
        uint  id;
        string firstName;
        course[] all_courses;
    }


    mapping(uint => student) public getstudent;
    
    function registerStudent(
        uint  _id,
        string memory _firstName
        ) public {
            student storage s = getstudent[_id];

            s.id = _id;
            s.firstName = _firstName;

            course memory c;
            c.name = "some course name";
            s.all_courses.push(c);

            s_counter ++; 
    }

    function addCourseToStudent(uint  _id) public {
        student storage s = getstudent[_id];

        course memory c;
        c.name = "some other course name";

        s.all_courses.push(c);
    }

    function getCourseOfStudent(uint _id) public view returns (course[] memory) {
        return getstudent[_id].all_courses;
    }
}

Node.js相关问答推荐

Node.js promise 循环中的所有多个API调用

NPM:一般的npm二进制依赖可以静态构建吗?

Node js 处理回调和 Promise

如何使用 Node.js 连接到 Cloud SQL?

密码加密的最佳实践是什么?

动态设置元数据,无需重复请求 NextJS 13

$not 的聚合版本是什么?

Indexeddb 获取所有不同于特定值的记录

Azure Function 在 2022 年 4 月 26 日禁用将用户字段设置为 HTTP 请求对象

自定义 Docker 容器 Github 操作无法在 /github/workspace 中找到 Node 脚本

如何在 mongoDB 中进行全动态搜索?

来自 Node-aws 的 Dynamo Local:所有操作都失败无法对不存在的表执行操作

eslint - vscode 的可选链接错误

构建 vue cli 后如何运行生产站点

Passport 登录和持久会话

TypeError:winston.Logger 不是带有winston 和morgan 的构造函数

为什么 Node 控制台不显示功能代码?

使用 Node.js 和 Express 进行简单的 API 调用

如何使用 cookie 创建 HTTP 客户端请求?

node --experimental-modules,请求的模块不提供名为的导出