Im creating a small program in which i have my files modularized, and i want to pass an array to a function in another file, but i cant get to pass it, since when i compile all my files it prompts me with:
undefined reference to `informesMain(Repartidor*, int)'
undefined reference to `repartidoresMain(Repartidor*, int)'
This is my main function, where i want to pass the array Repartidor repartidores[1120]
down the program:
#include <iostream>
#include <stdlib.h>
#include "./shared/utils/file-utils.h"
#include "./shared/model/repartidor.model.h"
#include "./entities/repartidores/repartidores-controller.h"
#include "./modules/reports-controller.h"
using namespace std;
void printMainMenu(bool error);
int main() {
unsigned userInput = 0;
bool error = false;
Repartidor repartidores[1120];
int cantidadRepartidoresActuales = 0;
do {
printMainMenu(error);
cin >> userInput; // TODO: Si el user mete un string, se rompe, handlear este caso y poner el error = true
switch (userInput) {
case 1:
error = false;
repartidoresMain(repartidores, cantidadRepartidoresActuales);
break;
case 2:
error = false;
informesMain(repartidores, cantidadRepartidoresActuales);
break;
case 0:
break;
default:
error = true;
}
} while(userInput != 0);
return 0;
}
void printMainMenu(bool error) {
system("cls");
if (error) cout<<"Opcion incorrecta!"<<endl<<endl;
cout<<"1 - Gestionar Repartidores"<<endl;
cout<<"2 - Informes"<<endl;
cout<<"0 - Salir"<<endl<<endl;
}
Then i got the respective header files for the used functions above:
#pragma once
#include "../../shared/model/repartidor.model.h"
void repartidoresMain(Repartidor[], int);
#pragma once
#include "../shared/model/repartidor.model.h"
void informesMain(Repartidor[], int);
And here's the implementation for those functions, respectively:
#include <iostream>
#include <stdlib.h>
#include "repartidores-controller.h"
#include "../../shared/model/repartidor.model.h"
using namespace std;
void printRepartidoresMenu(bool error);
void repartidoresMain(Repartidor repartidores, int cantidadRepartidoresActuales) {
unsigned userInput = 0;
bool error = false;
do {
printRepartidoresMenu(error);
cin >> userInput; // TODO: Si el user mete un string, se rompe, handlear este caso y poner el error = true
switch (userInput) {
case 1:
error = false;
// TODO: Funcion de alta definida en repartidores-actions.cpp
break;
case 0:
error = false;
return;
default:
error = true;
}
} while(userInput != 0);
}
void printRepartidoresMenu(bool error) {
system("cls");
if (error) cout<<"Opcion incorrecta!"<<endl<<endl;
cout<<"1 - Alta repartidor"<<endl;
cout<<"0 - Volver"<<endl<<endl;
}
#include "../shared/model/repartidor.model.h"
#include "./reports-controller.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
void printInformesMenu(bool);
void informesMain(Repartidor repartidores, int cantidadRepartidoresActuales)
{
unsigned userInput = 0;
bool error = false;
do {
printInformesMenu(error);
cin >> userInput; // TODO: Si el user mete un string, se rompe, handlear este caso y poner el error = true
switch (userInput) {
case 1:
error = false;
//TODO: Generar informe caso 1
break;
case 2:
error = false;
// TODO: Generar informe caso 2
break;
case 3:
error = false;
// TODO: Generar informe caso 3
break;
case 0:
return;
default:
error = true;
}
} while(userInput != 0);
}
void printInformesMenu(bool error)
{
system("cls");
if (error) cout<<"Opcion incorrecta!"<<endl<<endl;
cout<<"1 - Informar cantidad de repartidores por medio de transporte por zona"<<endl;
cout<<"2 - Informar medios de transportes no existentes (de todas las zonas)"<<endl;
cout<<"3 - Informar zonas con mas repartidores inscriptos"<<endl;
cout<<"0 - Volver"<<endl<<endl;
}
I want to mutate the array down the line, like when i just used a file, and passed an array as an argument, and i could mutate it as it was passed by reference by default, but i guess the problem is how im declaring that im passing the array in the .h files. Also i've seen people say "Declare a global variable in the .h file and use it" but i cant do that, if that would fix the issue.
I tried the following ways, with no success whatsover (in both declaration files)
void informesMain(Repartidor[], int);
void informesMain(Repartidor*, int);
void informesMain(Repartidor[1120], int);
void informesMain(Repartidor* [1120], int);