0

I'm trying to run an structure that one of the atributes is another structure, but I keep getting the error "does not name a type" and I'm not sure how to solve it.

Palabra.c

#include "palabra.h"
#include <stdlib.h>


struct nodoPalabra{
    Cadena contenido;
    nodoPalabra* sigPal;
};

Palabra.h

#ifndef PALABRA_H
#define PALABRA_H

#include "diccionario.h"
#include "editor.h"
#include "linea.h"


typedef struct nodoPalabra * Palabra;

Linea.c

#include "linea.h"
#include "palabra.h"
#include <stdlib.h>
#include<iostream>

struct nodoLinea{
    nodoLinea* sigLin;
    Palabra priPalab;       
};

Linea.h


#ifndef LINEA_H
#define LINEA_H

#include "editor.h"
#include "diccionario.h"
#include "palabra.h"


typedef struct nodoLinea * Linea;

Editor.h

#ifndef EDITOR_H
#define EDITOR_H


enum _retorno{
OK, ERROR, NO_IMPLEMENTADA
};
typedef enum _retorno TipoRetorno;

typedef unsigned int Posicion;
typedef char* Cadena;

#endif

I might be doing something wrong, but I've tried a lot of ways to solve it and wasn't able to fix it.

The error

  • 2
    You have circular dependencies, in other words one header includes the other, and vice versa. Instead you should use [forward declarations](https://stackoverflow.com/questions/4757565/what-are-forward-declarations-in-c) when appropriate. – Cory Kramer Oct 20 '21 at 18:10
  • To elaborate on what Cory said, consider that `#include` literally means "paste the contents of this file here". Consider what happens when `palabra.h` has `#include "linea.h"` and `linea.h` has `#include "palabra.h"` – AndyG Oct 20 '21 at 18:19
  • *"the error 'does not name a type'"* -- this is not a complete error message. Error messages use complete sentences, and this error message lacks a subject. What is the word that came right before this, the word that would serve as the subject of this sentence? (What is it that does not name a type?) Which line? Which source file are you compiling (and why have the other one present in your question)? This is information that needs to be in the question itself so that the question remains useful if the link goes dead. (See also what [ask] has to say about posting images of error messages.) – JaMiT Oct 20 '21 at 21:30

0 Answers0