0

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?

p. bosch
  • 139
  • 2
  • 10

1 Answers1

4

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

Also, avoid using namespace std, specially in headers.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • Okay this worked, thanks!! To avoid using 'using namespace std' what can I replace it with? – p. bosch Mar 10 '13 at 11:50
  • 2
    @p.bosch The reason you should not use *using namespace* in headers is, you will then bring that to every cpp file which includes the header, wether it wants it or not. If it is a "private" header only ever used in a single project, then it does not really matter. Otherwise, just write the namespace when using symbol from it, like: *std::string* – hyde Mar 10 '13 at 12:05