How to fix `invalid recursive type Tarea` error when trying to make `subtareas` a pointer to `ListaDeTareas` in Go?

王林
Release: 2024-02-11 12:30:09
forward
440 people have browsed it

当尝试在 Go 中使 `subtareas` 成为指向 `ListaDeTareas` 的指针时,如何修复 `invalid recursive type Tarea` 错误?

When using Go language, when we try to declare `subtareas` as a pointer to `ListaDeTareas`, we may encounter `invalid recursive type Tarea` error. This is because the Go language has some limitations on the processing of recursive types, which requires us to make some repairs. There are many ways to solve this problem. We can use interface types or structure nesting to solve this problem. Below I will detail how to fix this error.

Question content

I need the subtareas in struct tarea as a pointer to listadetareas but it doesn't work. I have invalid recursive type tarea

type Tarea struct {
    nombre    string
    duracion  float32

    subtareas *ListaDeTareas
}

type ListaDeTareas[T Tarea] struct {
    elementos listadetareas.LinkedList[Tarea]
}
Copy after login

Workaround

It appears that you are not using the type parameter t in listadetareas. Removing it will solve the problem.

type Tarea struct {
    nombre    string
    duracion  float32

    subtareas *ListaDeTareas
}

type ListaDeTareas struct {
    elementos listadetareas.LinkedList[Tarea]
}
Copy after login

The above is the detailed content of How to fix `invalid recursive type Tarea` error when trying to make `subtareas` a pointer to `ListaDeTareas` in Go?. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!