1

I have a problem. In my Qt project I'm having an error. Tt says:

multiple definition of estructura

I think it is because I'm using too many "#includes", but I don't know how to fix it.

This is my program:

Struct.h

 #ifndef STRUCT_H #define STRUCT_H #include <stdio.h> #include <string> struct Circulo{ std::string nombre; int capacidad; int statusMujer[4]; int hijos[4]; }; struct Circulo estructura[30]; #endif // STRUCT_H 

Logica.h

 #ifndef LOGICA_H #define LOGICA_H #include <iostream> void madresStatusCodificados(std::string , int , int[]); void ListadoDeCirculos(int, int , std::string []); std::string CirculoMayorCapacidad(int ); int NinnosEnCirculosconStatus(int , int ); void Listado(int); #endif // LOGICA_H 

interfaz.cpp

#include <Interfaz/Interfaz.h> #include <Logica/Defecto.h> #include <Interfaz/Menu.h> #include <Logica/Struct.h> #include <iostream> using namespace std; void Principal(){ cin>>estructura[i].statusMujer[3]; cout<<"Escriba la cantidad de hijos con madres desconocidas"<<endl; cin>>estructura[i].hijos[3]; i++; }else{ break; } } } 

Logica.cpp

#include <iostream> using namespace std; //#include <Logica/Logica.h> #include <Logica/Struct.h> void madresStatusCodificados(string t, int h , int k[]){ for(int i=0;i<h;i++){ if(estructura[i].nombre==t){ k[0]=estructura[i].statusMujer[0]; k[1]=estructura[i].statusMujer[1]; k[2]=estructura[i].statusMujer[2]; k[3]=estructura[i].statusMujer[3]; } } } void ListadoDeCirculos(int g,int u,string h[]){ for(int i=0;i<u;i++){ if(estructura[i].statusMujer[g-1]!=0) h[i]=estructura[i].nombre; } } string CirculoMayorCapacidad(int k){ int n=-1; string l; for(int i=0;i<k;i++){ if(estructura[i].capacidad>n){ n=estructura[i].capacidad; l=estructura[i].nombre; } } return l; } int NinnosEnCirculosconStatus(int a,int b){ int h=0; for(int i=0;i<b;i++){ h=h+estructura[i].hijos[a-1]; } return h; } void Listado(int y){ for(int i=0;i<y;i++){ cout<<"NOMBRE DEL CIRCULO CAPACIDAD Madres solteras Madres trabajadoras Madres caso social Madres desconocidas "<<endl; cout<<estructura[i].nombre<<""<<estructura[i].capacidad<<estructura[i].statusMujer[0]<<estructura[i].statusMujer[1]<<estructura[i].statusMujer[2]<<estructura[i].statusMujer[3]<<endl; } } 

I am getting this error: Errors

1

2 Answers 2

2

You have defined a variable named "estructura" in several files, the error tells you that it was first defined in Struct.h being called #included in Logica.cpp,

struct Circulo estructura[30]; 

you have another definition the the file Defecto.h or a file included by Defecto.h

Sign up to request clarification or add additional context in comments.

Comments

2

Move the definition of estructura in a cpp file of your choice, then declare it as extern wherever you need it. And you can omit the struct keyword, in c++.

In a struct.cpp file:

#include "Struct.h" Circulo estructura[30]; 

In your Logica.cpp and Interfaz.cpp files:

#include "Struct.h" extern Circulo estructura[30]; 

Here is a long and detailed explanation of your issue.

3 Comments

Do you mean,put the estructura declaration in a .cpp file,and declare this declaration as extern??Thanks in advance
Already did that,so,now,do i have to declare estructura in all .cpp files?Thanks in advance
I edited the answer to better explain what you have to do. Please read the answer in the link I provided to understand why you have to do so.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.