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

huangapple go评论77阅读模式
英文:

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

问题

我需要将结构体Tarea中的subtareas指针指向ListaDeTareas,但是目前无法正常工作。我得到了"invalid recursive type Tarea"的错误。

type Tarea struct {
	nombre    string
	duracion  float32

	subtareas *ListaDeTareas
}

type ListaDeTareas[T Tarea] struct {
	elementos listadetareas.LinkedList[Tarea]
}
英文:

I need subtareas in the struct Tarea to be a pointer to ListaDeTareas, but is not working. I have invalid recursive type Tarea

type Tarea struct {
	nombre    string
	duracion  float32

	subtareas *ListaDeTareas
}

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

答案1

得分: 0

似乎你在 ListaDeTareas 中没有使用类型参数 T,移除它可能会解决这个问题。

type Tarea struct {
    nombre    string
    duracion  float32

    subtareas *ListaDeTareas
}

type ListaDeTareas struct {
    elementos listadetareas.LinkedList[Tarea]
}
英文:

It seems that you don't use type parameter T in ListaDeTareas. And removing it will fix the issue.

type Tarea struct {
    nombre    string
    duracion  float32

    subtareas *ListaDeTareas
}

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

huangapple
  • 本文由 发表于 2023年6月4日 05:19:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76398075.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定