Circular dependency! Assuming string
type is well-defined somewhere else in the header files (maybe std::string
?), this is because you included the files in the wrong order.
#include "login.h"
#include "lista.h"
....
This is basically equivalent to:
struct account
{
string user = "";
int hash_pass = 0;
};
struct list
{
lista* a;
int size;
};
struct elem
{
account info;
elem* next;
};
typedef elem* lista;
....
As you can see, lista
appears even before the typedef
, which is why you're getting an error.
Obviously you do not want to care about in which order you are including the header files, so the right solution here would be to include lista.h
in login.h
with proper header guards. But that is not enough in this case: there is a circular dependency here, as lista.h
needs struct account
from login.h
and login.h
needs lista
from lista.h
. Therefore, we add a forward declaration as well. See this link for more info. Your final code would then be:
lista.h
:
#ifndef LISTA_H_
#define LISTA_H_
struct account; // forward declaration
struct elem
{
account* info; // notice that `account` now has to be a pointer
elem* next;
};
typedef elem* lista;
#endif
login.h
:
#ifndef LOGIN_H_
#define LOGIN_H_
#include "lista.h"
struct account
{
string user = "";
int hash_pass = 0;
};
struct list
{
lista* a;
int size;
};
#endif