CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2009
    Posts
    8

    Problem with includes

    Hello i have a problem with includes. The situation is like this:

    -Concepts: (NOTE: "....." is to separate the parts of the diagram and make it understable....)

    I am designing a program in 3-tier achitecture. The class diagram is like this:

    ControladorDomini (domain controller)
    | ....... \
    Soci .... Abonat
    ............. |
    ............. Tarifa

    Now, i want to relation Soci and Tarifa to a new class called Servei. The design should be in that way.

    So it would be:

    ControladorDomini (domain controller)
    | ....... \
    Soci Abonat
    | ....... |
    \ ....... Tarifa
    \ ....... /
    \ ....... /
    Serveis

    -Code:
    ControladorDomini.h
    Code:
    #ifndef _DOMINI_H_
    #define _DOMINI_H_
    
    #include "Abonat.h"
    //#include "Servei.h"
    #include "Soci.h"
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <stdlib.h>
    #include <vector>
    #include <map>
    #include "ControladorDades.h"
    #include <time.h>
    #include <direct.h>
    
    using namespace std;
    
    class ControladorConsola;
    class ControladorDades;
    
    class ControladorDomini {
    private:
        //atributs
    	ControladorConsola* _cc;
    	ControladorDades* _cbd;
    	//ControladorPantalla _cp;
    	map<int,Abonat> _abonats;//key el num
    	map<int,Soci> _socis;//key el num
    	fstream _log;
    	time_t _tempsLog;
    	bool _connectat;
    	bool _estable;
    
    public:
        //functions.....
    
    };
    
    #endif
    Soci.h
    Code:
    #include <iostream>
    #include <string>
    #include <map>
    #include <vector>
    #include "Servei.h"
    
    using namespace std;
    
    
    class Soci{
    private:
        //atributs
        int _id;
        int _numSoci;
        int _llicencia;
        string _dni;
        string _nom;
        string _cognoms;
        string _telefon;
        string _email;
        bool _actiu;
        map<int,Servei> _serveis;
    
    public:
        //functions....
    
    };
    Abonat.h
    Code:
    #include <iostream>
    #include <string>
    #include <map>
    #include "Tarifa.h"
    #include <vector>
    
    using namespace std;
    
    class Abonat{
    private:
        //atributs
        int _id;
        int _numAbonat;
        string _cif;
        string _nom;
        string _telefon;
        string _email;
        string _direccio;
        string _poblacio;
        string _codiPostal;
        bool _actiu;
        map<string,Tarifa> _tarifes;
    public:
        //functions...
    
    };
    Tarifa.h
    Code:
    #include <iostream>
    #include <string>
    #include <vector>
    #include <map>
    #include "Servei.h"
    
    using namespace std;
    
    
    class Tarifa {
    private:
        //atributs
        int _id;
        string _codi;
        float _import;
        float _importSoci;
        int _idAbonat;
        bool _actiu;
        map<int,Servei> _serveis;
    public:
        //functions...
    
    };
    I think that the problem is that in ControladorDomini.h, Servei.h is included 2 times: one coming from Soci.h and the other coming from Tarifa.h -> Abonat.h

    I need have acces to Servei in Soci and in Tarifa... so i don't know how to solve it....

    The compiler error is like this:

    Servei.h(7) : error C2011: 'Servei' : nueva definición del tipo 'class'
    1> Servei.h(7) : vea la declaración de 'Servei'

    The translation:

    Servei.h(7) : error C2011: 'Servei' : new definition from type 'class'
    1> Servei.h(7) : go to the declaration of 'Servei'

    Thank you very much for the help!!!!

    Imanol.

  2. #2
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: Problem with includes

    Add include guards (the #ifndef/#define/#endif directoives) to all include files. You have them in ControladorDomini.h but they are lacking from other files.
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured