p. bosch
p. bosch

Reputation: 139

Class inside a class in c++

I have one class defined and working which is TempsSet. But now I need to make a new one that uses TempsSet. This is the class definition I have for the new one:

#ifndef SESSIO_H
#define SESSIO_H

    class sessio {
        public:
            // constructors
            sessio();
            //Pre: --; //Post:posa el temps per defecte a (0,0)
            sessio(string d, int h, int dur, string nom);
            // Pre: --; Post: el temps sera (DL h,m,s)
            void mostrarS() const;
            //Pre: --; Post: mostra per pantalla l'horari d'una activitat
            void llegirS();
            //Pre: --; Post: llegeix per teclat l'horari d'una activitat
        private:
            TempsSet a_sess;
            int a_dur;
            string a_nom;
    };

    #endif // SESSIO_H

And this is the class definition of TempsSet. This one works perfectly:

#ifndef TEMPSSET_H
#define TEMPSSET_H
using namespace std;

class TempsSet {
 public:
    // constructors
    TempsSet();
    //Pre:-- //Post:posa el temps per defecte a (0,0)
    TempsSet(string d, int h, int m, int s);
    // Pre:--; Post: el temps sera (DL h,m,s)

    // mètodes consultors
    string diaLlarg() const;
    //Pre: Dia entrat correctament; Post: retorna el dia sense abreviar
    string diaAbr() const;
    //Pre: Dia entrat correctament; Post: retorna el dia abreviat
    int hora() const;
    // Pre: Hora entrada correctament; Post: retorna les hores del temps
    int minut() const;
    // Pre: Minuts entrat correctament; Post: retorna els minuts del temps
    int segon() const;
    // Pre: Segon entrat correctament; Post: retorna el segons del temps
    bool esIgual(TempsSet t) const;
    //Pre: Els dos temps entrats correctament; Post: retorna cert si els dos temps són iguals
    bool esMajor(TempsSet t) const;
    //Pre: Els dos temps entrats correctament; Post:retorna cert si el temps actual és major que el paràmetre
    void mostrar() const;
    //Pre: Els temps entrats correctament; Post: mostra el temps per pantalla en format d:h:m:s
    void mostrarLlargs() const;
    //Pre: Els temps entrats correctament; Post: mostra el temps per pantalla en format sense abreviar
    void mostrarDHM() const;
    //Pre: Els temps entrats correctament; Post: mostra el temps en format d:h:m

    // mètodes modificadors
    void llegir();
    //Pre: h≥0 i 0≤m<60 i 0≤s<60 sino s'ha de tornar a introduir el valor; Post: llegeix el temps des de teclat en format h:m:s.
    void llegirDHM();
    //Pre: h≥0 i 0≤m<60 sino s'ha de tornar a introduir el valor; Post: llegeix el temps des de teclat en format h:m.
    void incr(int s);
    //Pre: h≥0 i 0≤m<60 i 0≤s<60; Post: incrementa el temps en el nombre de segons indicat
    void incr (int d, int h, int m, int s);
    //Pre--; Post: incrementa el temps en el nombre d’hores, minuts i segons indicats
    void decr(int s);
    //Pre: h≥0 i 0≤m<60 i 0≤s<60; Post: decrementa el temps en el nombre de segons indicats
    void decr(int d, int h, int m, int s);
    //Pre: h≥0 i 0≤m<60 i 0≤s<60; Post: decrementa el temps en el nombre d’hores, minuts i segons indicats

 private:
    int a_s;
    int a_d;
};

#endif // TEMPS_H

But when I try to compile, It says weird errors, that I'm missing a parenthesis after the 'd' from this line:

sessio(string d, int h, int dur, string nom);

That TempsSet does not name a type and it points to the private attributes of sessio. Any ideas? How can I solve this issues?

Upvotes: 0

Views: 407

Answers (1)

juanchopanza
juanchopanza

Reputation: 227370

sessio requires the full TempSet class definition in its header. So, #include "TempSet.h".

Also, avoid using namespace std, specially in headers.

Upvotes: 4

Related Questions