Error message when compiling a struct array as an attribute

1

I do not know how to create an attribute of type struct array. I leave my codes, I get this error:

In classAntena.h it says 'cellular' was not declared in this scope. In classAntena.cpp it says 'Cell phones' does not name a type.

classAntena.h

#ifndef CLASSANTENA_H_
#define CLASSANTENA_H_


class Antena{

private:
    Celular celulares[100];

public:
    void incrementarLlamadasRealizadas(int);
    void incrementarLlamadasRecibidas(int);
    void incrementarDuracionLlamadas(int,int);
    void modificarInicioLlamada(int,int);
    void modificarFinLlamada(int,int);
    int devolverLlamadasRealizadas(int);
    int devolverLlamadasRecibidas(int);
    int devolverDuracionLlamadas(int);
    int devolverNumeroCelular(int);

};

#endif /* CLASSANTENA_H_ */

classAntena.cpp

#include "classAntena.h"

struct Celular{

    int numeroCelular;
    int cantLlamadasRealizadas;
    int cantLlamadasRecibidas;
    int duracionLlamadas;
    int inicioLlamada;
    int finLlamada;
};

void Antena::incrementarLlamadasRealizadas(int posCel){

    celulares[posCel].cantLlamadasRealizadas++;
}

void Antena::incrementarLlamadasRecibidas(int posCel){

    celulares[posCel].cantLlamadasRecibidas++;
}

void Antena::incrementarDuracionLlamadas(int duracionLlamada, int posCel){

    celulares[posCel].duracionLlamadas += duracionLlamada;
}

void Antena::modificarInicioLlamada(int comienzoDeLlamada, int posCel){

    celulares[posCel].inicioLlamada = comienzoDeLlamada;
}   

void Antena::modificarFinLlamada(int finDeLlamada, int posCel){

    celulares[posCel].finLlamada = finDeLlamada;
    int duracionLlamada = celulares[posCel].finLlamada - celulares[posCel].inicioLlamada;
    incrementarDuracionLlamadas(duracionLlamada, posCel);
}

int Antena::devolverLlamadasRealizadas(int posCel){

    return celulares[posCel].cantLlamadasRealizadas;
}

int Antena::devolverLlamadasRecibidas(int posCel){

    return celulares[posCel].cantLlamadasRecibidas;
}

int Antena::devolverDuracionLlamadas(int posCel){

    return celulares[posCel].duracionLlamadas;
}

int Antena::devolverNumeroCelular(int posCel){

    return celulares[posCel].numeroCelular;
}
    
asked by xfxrxaxn 29.03.2016 в 02:02
source

1 answer

2

You have two problems:

  • The definition of struct Celular must be in the .h file before the definition of the class. Otherwise, the compiler can not know what Celular is.

  • In your class Antena the field is defined to support 1 single element, it is not an array. Change the statement to be an arrangement:

    Celular celulares[];
    
  • answered by 29.03.2016 / 05:17
    source