i keep getting the an error that was supposed to happen if i haven’t had pre-declared the structures used before its definition, but i did!!: “typedef struct campeonato campeonato; typedef struct jogo jogo;” (as shown in the code below). Can anyone tell me why I’m getting the following errors and what’s wrong with my code:
c:21: error: redefinition of typedef 'campeonato'
c:5: error: previous declaration of 'campeonato' was here
c:29: error: redefinition of typedef 'jogo'
c:6: error: previous declaration of 'jogo' was here
and the piece of code that generates those errors is…
typedef struct campeonato campeonato;
typedef struct jogo jogo;
typedef struct time{
char nome[32];
//existe uma correspondencia entre jogos[i][] e campeonatos[i]
jogo *jogosDeCadaCampeonato;
campeonato *campeonatos[];
}time;
typedef struct campeonato{
char nome [100];
int nro_participantes;
int nro_jogos;
time *times;
jogo *jogos;
}campeonato;
typedef struct jogo{
time* timeA;
time* timeB;
time* vencedor;
int golsA;
int golsB;
}jogo;
Is not a forward declaration. It’s a typedef. A forward declaration would simply be:
As it is now, you typedef campeonato and jogo twice, hence the error.
Note that using the forward declaration will allow you to use the structs before they are defined, you’d still have to use them as
struct campeonatointimeandstruct jogoincampeonato.