Home > Article > Backend Development > How to fix `invalid recursive type Tarea` error when trying to make `subtareas` a pointer to `ListaDeTareas` in Go?
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.
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] }
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] }
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!