IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Problème d'inclusions ( hé oui encore)


Sujet :

C++

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 42
    Points : 28
    Points
    28
    Par défaut Problème d'inclusions ( hé oui encore)
    bonsoir ,

    j'espère vous embéter pour la dernière fois avec ce projet mais la g tout recommencer proprement (enfin plus proprement )

    je m'explique g une classe faune qui utilise une classe animal et vice-verca ,
    pour éviter les problèmes d'inclusion cyclique g utilisé les forward déclaration sur vos conseil avisés , mais g toujours des problèmes car le compilateur me sort des références non définis sur toutes les méthodes d'animal.

    voici les source , si quelq'un à le courage de s'y plonger pour voir ou se situe le problème il me rendrait un grand service ( pour ma part je pense que ça merde au niveau des inclusion

    Animal.h :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
     
    #ifndef _ANIMAL
    #define _ANIMAL
     
    #include "./Para.h"
     
    #include "./Monde.h"
    #include <time.h>
    #include <math.h>
    #include <iostream>
    using namespace std;
     
     
    int refGenerale=0;
     
    class Faune;
     
     
    class Animal{
          int wAge;
          int wSex; // 0 male, 1 femelle
          bool wIfDead;
          int wEnergy;
          int wRef;
          bool wIfReprod;
          char wType;
          Herbe* wPos;
                 public:
                        Animal();                  
                        virtual ~Animal();
     
                        int getAge();
                        int getSex();
                        bool getIfDead();
                        int getEnergy();
                        int getRef();
                        bool getIfReprod();
                        char getType();
                        int getX();
                        int getY();
                        int getNbRabbit();
                        int getNbFox();
                        int getHauteurHerbe();
                        Herbe* getPos();
     
     
     
                        void vieillir();
                        void setSex(int);
                        void setIfDead(bool);
                        void setEnergy(int);
                        void addEnergy(int);
                        void subEnergy(int);
                        void setIfReprod(bool);
                        char setType(char );
                        void setPos(Herbe* );
     
     
                        virtual void trySeDeplacer(Monde &) = 0;
                        virtual void trySeReproduire(Faune &) =0;
                        virtual void tryManger(Faune &) =0; 
     
                        };
     
     
    class Lapin:public Animal{
    public:
           Lapin();
           Lapin(int s);
           ~Lapin();
     
          void avoirBebeLapin(Faune &,  int);
     
          bool cherchePartenaireLapin(Faune &,int);
     
     
     
          void trySeDeplacer(Monde &);
          void trySeReproduire(Faune &);
     
     
          void tryManger(Faune &);
          };
     
    class Renard:public Animal{
          public:
                 Renard();     
                 Renard(int s);
                 ~Renard();
     
     
                 void avoirBebeRenard(Faune &,  int);
     
                 bool cherchePartenaireRenard(Faune &,int);
     
    void trySeDeplacer(Monde &);
    void trySeReproduire(Faune &);
    void tryManger(Faune &);
    };
     
    #endif // _ANIMAL
    animal.cpp :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
     
    #include "./Animal.h"
    #include "./Faune.h"
                        Animal::Animal(){
                                 cout<<"Constructeur d'Animal\n";
                                   wAge = 0;
                     wIfDead = false;
                     wRef = refGenerale++;
                     wIfReprod = false;
                     wPos = NULL;
                     }
     
                        Animal::~Animal(){
                                cout<<"Destructeur d'animal\n";
                                 if (wPos != NULL) delete wPos;
     
                      }
     
                        int Animal::getAge(){return wAge;}
                        int Animal::getSex(){return wSex;}
                        bool Animal::getIfDead(){return wIfDead;}
                        int Animal::getEnergy(){return wEnergy;}
                        int Animal::getRef(){return wRef;}
                        bool Animal::getIfReprod(){return wIfReprod;}
                        char Animal::getType(){return wType;}
                        int Animal::getX(){return wPos->X;}
                        int Animal::getY(){return wPos->Y;}
                        int Animal::getNbRabbit(){return wPos->nbRabbitMale + wPos->nbRabbitFemelle;}
                        int Animal::getNbFox(){return wPos->nbFoxMale + wPos->nbFoxFemelle;}
                        int Animal::getHauteurHerbe(){return wPos->hauteurHerbe;}
                        Herbe* Animal::getPos(){return wPos;}
     
     
     
                        void Animal::vieillir(){wAge = wAge+1;}
                        void Animal::setSex(int s){wSex = s;}
                        void Animal::setIfDead(bool d){ wIfDead = d;}
                        void Animal::setEnergy(int e){ wEnergy = e;}
                        void Animal::addEnergy(int e){wEnergy = wEnergy + e;}
                        void Animal::subEnergy(int e){wEnergy = wEnergy - e;}
                        void Animal::setIfReprod(bool r){wIfReprod = r;}
                        char Animal::setType(char c){wType = c;}
                        void Animal::setPos(Herbe* h){wPos = h;}
     
     
           Lapin::Lapin():Animal(){
                            cout<<"Constructeur de Lapin \n";
                    Animal::setType('r');
                    Animal::setEnergy(tabInfo[9]);
                    }
           Lapin::Lapin(int s):Animal(){
                     Animal::setType('r');
                     Animal::setEnergy(tabInfo[9]);
                     Animal::setSex(s);
                     }
     
     
           Lapin::~Lapin(){cout<<"Destructeur de Lapin\n";}
     
     
     
     
     void Lapin::trySeDeplacer(Monde &m){
               if(getEnergy()>tabInfo[11] && getHauteurHerbe()>tabInfo[5])//nrj ok et hauteurHeubre trop petite pour se nourrir
                               {
                                int best_X=0,best_Y=0,max=0,i_bis=0,j_bis=0;
                                for(int i=(this->getX()-1);i<=(this->getX()+1);i++)
                                        {
                                         for(int j=(this->getY()-1);j<=(this->getY()+1);j++)
                                                 {
                                                  //mise à jour des coord pour monde torique
                                                  i_bis=i;
                                                  j_bis=j;
                                                  if(i<0)i_bis=tabInfo[0]-1;
                                                  if(i>=tabInfo[0])i_bis=0;
                                                  if(j<0)j_bis=tabInfo[0]-1;
                                                  if(j>tabInfo[0])j_bis=0;
     
                                                  if(m.getCase(i_bis,j_bis).hauteurHerbe>max)
                                                                                            {
                                                                                             max=m.getCase(i_bis,j_bis).hauteurHerbe;
                                                                                             best_X=i_bis;
                                                                                             best_Y=j_bis;  
                                                                                            } 
                                                 }                     
                                        }
                                 if(best_X != this->getX() || best_Y != this->getY())
                                           {
                                            if(getSex()==0) getPos()->nbRabbitMale--;    
                                            else this->getPos()->nbRabbitFemelle--;   
     
                                            setPos(m.getPtrCase(best_X,best_Y));
                                            setEnergy(getEnergy()-tabInfo[20]);
     
                                            if(getSex()==0)this->getPos()->nbRabbitMale++;    
                                            else this->getPos()->nbRabbitFemelle++;   
                                           }     
     
                               }  } //à définir
     
     
     
     
     
     
          void Lapin::tryManger(Faune &f){cout<<"Miam une carotte\n";}//à définir
     
     
     
                 Renard::Renard():Animal(){
                                   cout<<"Constructeur de renard \n";
                            Animal::setType('f');
                            Animal::setEnergy(tabInfo[10]);
                            }     
                 Renard::Renard(int s):Animal(){
                             Animal::setType('f');
                             Animal::setEnergy(tabInfo[10]);
                             Animal::setSex(s);
                             }
                 Renard::~Renard(){cout<<"Destructeur de Renard\n";}
     
     
    void Renard::trySeDeplacer(Monde &m){if(getEnergy()>tabInfo[12] && getNbRabbit()==0)//nrj ok et plus de Lapin sur la case
                                           {
     
                                            int best_X=0,best_Y=0,max=0,i_bis=0,j_bis=0;
                                            for(int i=(this->getX()-1);i<=(this->getX()+1);i++)
                                                    {
                                                     for(int j=(this->getY()-1);j<=(this->getY()+1);j++)
                                                             {
                                                              i_bis=i;
                                                              j_bis=j;
                                                              if(i<0)i_bis=tabInfo[0]-1;
                                                              if(i>=tabInfo[0])i_bis=0;
                                                              if(j<0)j_bis=tabInfo[0]-1;
                                                              if(j>tabInfo[0])j_bis=0;
     
                                                              if(m.getCase(i_bis,j_bis).nbRabbitMale+m.getCase(i_bis,j_bis).nbRabbitFemelle>max)
                                                                                                        {
                                                                                                         max=m.getCase(i_bis,j_bis).nbRabbitMale+m.getCase(i_bis,j_bis).nbRabbitFemelle;
                                                                                                         best_X=i_bis;
                                                                                                         best_Y=j_bis;
                                                                                                        } 
                                                             }                     
                                                    }
                                             if(best_X != this->getX() || best_Y != this->getY())
                                                       {
                                                        if(getSex()==0) getPos()->nbFoxMale--;    
                                                        else this->getPos()->nbFoxFemelle--;   
     
                                                        setPos(m.getPtrCase(best_X,best_Y));
                                                        setEnergy(getEnergy()-tabInfo[19]);
     
                                                        if(getSex()==0)this->getPos()->nbFoxMale++;    
                                                        else this->getPos()->nbFoxFemelle++;   
                                                       }     
     
                                           }                   
     
    } 
     
    void Renard::trySeReproduire(Faune &f){cout<<"Oh oui fox prend moi\n";} //à définir 
    void Renard::tryManger(Faune &f){cout<<"miam un lapin\n";}//à définir
     
     
     
     
     
     
    void Renard::avoirBebeRenard(Faune &f,  int n){
               int i = 0;
               while( i != n){
                        Renard* r = new Renard(rand()%2);
                        r->setPos(this->getPos());
                        f.addAnimal(r);
                        tabRapport[8]++;
                        i++;
                      }
          }
     
    void Lapin::avoirBebeLapin(Faune &f,  int n){
               int i = 0;
               while( i != n){
                                       Lapin* l = new Lapin(rand()%2);
                                       l->setPos(this->getPos());
                                       f.addAnimal(l);
                                       tabRapport[7]++;
                                       i++;
                                       }
               }
     
     
           bool Lapin::cherchePartenaireLapin(Faune &f, int n){
                               if(f[n]->getX() == this->getX && f[n]->getY() == this->getY())
                                               if(f[n]->getType() == 'r')
                                                  if(this->getSex() == 0){ // si l'instance est un male
                                                    if(f[n]->getSex() == 1)//on cherche une femelle
                                                       if(f[n]->getIfReprod() == false)
                                                          if(f[n]->getAge()<= tabInfo[15])
                                                             return true;
                                                       }
                                                       else{ // si l'instance est une femelle
                                                         if(f[n]->getSex() == 0)//on cherche un male
                                                            if(f[n]->getAge()<= tabInfo[15])
                                                               return true;
                                                             }
     
     
     
           return false;
           }
     
           bool Renard::cherchePartenaireRenard(Faune &f, int n){
                               if(f[n]->getX() == this->getX && f[n]->getY() == this->getY())
                                               if(f[n]->getType() == 'f')
                                                  if(this->getSex() == 0){ // si l'instance est un male
                                                    if(f[n]->getSex() == 1) // on cherche une femelle
                                                       if(f[n]->getIfReprod() == false)
                                                          if(f[n]->getAge()<= tabInfo[16])
                                                             return true;
                                                             }
                                                  else{
                                                       else{ // si l'instance est une femelle
                                                         if(f[n]->getSex() == 0)//on cherche un male
                                                            if(f[n]->getAge()<= tabInfo[16])
                                                               return true;
                                                             }
           return false;
           }
     
    void Lapin::trySeReproduire(Faune &f){
     
         // vérification de l'age mini de reproduction
         if(this->getAge()<= tabInfo[15]){ //si en age de reprod
            if(this->getSex() == 0){ // si male
               if(this->getPos()->nbRabbitFemelle != 0){ // s'il y a des lapin femelle sur la case
                  int nb_max = this->getEnergy() / tabInfo[13]; 
                  int i = 0;
                  while(i != f.getSize() && i != nb_max){
                          if(this->cherchePartenaireLapin(f, i)){ // Vrai si l'instance courante dans f est une lapine qui peut se reprod
                               f[i]->setIfReprod(true); // la femelle va se reproduire
                               this->avoirBebeLapin(f,rand()%4); // elle a au max 4 bébé
                               f[i]->subEnergy(tabInfo[13]); // on baisse son energie
                               if(f[i]->getEnergy() <= 0)f[i]->setIfDead(true);//si son energie tombe a zero elle meurt
                               }
                  i++;
                            }
                          }
                       }
            else{ //c'est une femelle
                if(this->getPos()->nbRabbitMale != 0){ // s'il y a des lapin males sur la case
                  int nb_max = this->getEnergy() / tabInfo[13]; 
                  int i = 0;
                  while(i != f.getSize() && i != nb_max){
                          if(this->cherchePartenaireLapin(f, i)){ // Vrai si l'instance courante dans f est un lapin qui peut se reprod
                               this->setIfReprod(true); // la femelle(instance courante) va se reproduire
                               this->avoirBebeLapin(f,rand()%4); // elle a au max 4 bébé
                               this->subEnergy(tabInfo[13]); // on baisse son energie
                               if(this->getEnergy() <= 0)this->setIfDead(true);//si son energie tombe a zero elle meurt
                               }
                  i++;
                            }
                          }
                       }
     
                  }
    Faune.h

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
     
    #ifndef _FAUNE
    #define _FAUNE
    #include "./Animal.h"
    #include "./Para.h"
    #include <vector>
    #include <iostream>
    using namespace std;
     
     
     
    typedef vector<Animal*> VecAnim;
     
    class Faune:private VecAnim{
          public:
            Faune():VecAnim(){cout<<"constructeur de faune\n";}
            ~Faune(){
                     cout<<"Destructeur de faune\n";
                     VecAnim::iterator i;
                     for(int i=0;i<this->getSize();i++)delete this->operator[](i);
                     this->clear();
                    }
            int getSize(){return this->size();}
            void addAnimal(Animal* a)
                 {
                 this->push_back(a);
                 //si lapin
                     if( a->getType() == 'r'){
                         //si male
                         if(a->getSex()== 0) a->getPos()->nbRabbitMale++;
                         //si femelle lapin
                         else a->getPos()->nbRabbitFemelle++;
                         }
                     else{//si renard
                         //si male
                         if(a->getSex()== 0) a->getPos()->nbFoxMale++;
                         //si femelle renard
                         else a->getPos()->nbFoxFemelle++;
                         }
     
     
                 }
            void delAnimal(int ref)
                 {
                 int i=0;
                 VecAnim::iterator ite;
                 ite=this->begin();
                 while (i != this->getSize() && this->operator[](i)->getRef() != ref) {
                 i++;ite++;}
                 if( i!=this->getSize())
                     {
                     //si lapin
                     if( this->operator[](i)->getType() == 'r'){
                         //si male
                         if(this->operator[](i)->getSex()== 0) this->operator[](i)->getPos()->nbRabbitMale--;
                         //si femelle lapin
                         else this->operator[](i)->getPos()->nbRabbitFemelle--;
                         }
                     else{//si renard
                         //si male
                         if(this->operator[](i)->getSex()== 0) this->operator[](i)->getPos()->nbFoxMale--;
                         //si femelle renard
                         else this->operator[](i)->getPos()->nbFoxFemelle--;
                         }
     
                     delete this->operator[](i);
                     this->operator[](i)=NULL;
                     this->erase(ite,ite);
                     }
                 }
            Animal* seekAnimal(int ref)
                    {
                     int i=0;
                     while (i != this->getSize() && this->operator[](i)->getRef() != ref) i++;
                     if( i!=this->getSize()) return this->operator[](i);
                     }        
            Animal* & operator[](int i)
                    {
                     return *(begin() + i);
                    }
     
          // verif si la bestiole à fait son temps 
          bool ifDeadAge(int i){
               //si Lapin
               if(this->operator[](i)->getType() == 'r'){
                   if( this->operator[](i)->getAge()> tabInfo[1]) return true;
                   }
               else{// si Renard
                    if( this->operator[](i)->getAge()> tabInfo[2]) return true;
                    }
                    return false; 
               }
     
          // fin de tour : mettre reprod a false , vieillir, mourir les vieux,
     
          void finDeTour(){
               int i;
               for( i=0;i != this->getSize();i++){
                    this->operator[](i)->vieillir();
                    if( this->ifDeadAge(i)) this->delAnimal(this->operator[](i)->getRef());
                    if(this->operator[](i)->getSex() == 1 && this->operator[](i)->getIfReprod() == true)
                          this->operator[](i)->setIfReprod(false);
                    if(this->operator[](i)->getIfDead() ==true) this->delAnimal(this->operator[](i)->getRef());
                          }
                    }
     
     
    };
     
    #endif //_FAUNE
    Dans le main() j'inclus Faune.h qui inclut lui-même Animal.h donc je pense que c'est bon.

    voila si quelqu'un a une solution ou désire un complément d'information ou de code ya pas de soucis !

    merci à vous , bonne soirée !

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    125
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 125
    Points : 145
    Points
    145
    Par défaut
    dans ton animal.h

    le compilo aime pas la declaration de la variable :
    int refGenerale=0;

    si tu ve faire une globale il faut la mettre dans 1 fichier C et mettre
    extern int refGenerale; dans le H
    sinon le compilo tente de faire une variable du meme nom sur tous les fichiers C

    sinon pour le pb de lien croise ca marche chez moi !

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 42
    Points : 28
    Points
    28
    Par défaut
    yop , merci pr le extern , g fais ça, par contre ça m'étonne ske tu di que les dépendances marches !

    appelle une méthodes d'animal dans le main() ça te fera de suite une erreur de linkage sur cette méthode

    ça ma croké la tête mais je vois tjs pas comment le solutionner !

    merci bonne journée

  4. #4
    Membre régulier Avatar de telliam
    Inscrit en
    Octobre 2006
    Messages
    63
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 63
    Points : 71
    Points
    71
    Par défaut
    Citation Envoyé par porco
    yop , merci pr le extern , g fais ça, par contre ça m'étonne ske tu di que les dépendances marches !

    appelle une méthodes d'animal dans le main() ça te fera de suite une erreur de linkage sur cette méthode

    ça ma croké la tête mais je vois tjs pas comment le solutionner !

    merci bonne journée
    peux tu mettre les erreurs du compilo?

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    125
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 125
    Points : 145
    Points
    145
    Par défaut
    tu nous as pas fille parra et monde donc j ai un peut fait le menage pour n'avoir que animal faune les 2 3 methodes qui l'utilisent

    y a pas de pb tu as fait une declaration anticipee donc ca marche chez moi et je cree un lapin

    donnes tes erreurs

  6. #6
    Membre régulier Avatar de telliam
    Inscrit en
    Octobre 2006
    Messages
    63
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 63
    Points : 71
    Points
    71
    Par défaut
    Citation Envoyé par alskaar
    tu nous as pas fille parra et monde donc j ai un peut fait le menage pour n'avoir que animal faune les 2 3 methodes qui l'utilisent

    y a pas de pb tu as fait une declaration anticipee donc ca marche chez moi et je cree un lapin

    donnes tes erreurs
    ouah, j'espère que tu codes pas comme tu écris en français

  7. #7
    Membre habitué
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    125
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 125
    Points : 145
    Points
    145
    Par défaut
    bin si, mes noms de variables sont comme ca

  8. #8
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 42
    Points : 28
    Points
    28
    Par défaut Monde.h, para.h Herbe.h + erreur de compile
    voila le reste du code en tout cas merci d'y passer un peu de tps c cool de votre part :

    Herbe.h

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    #ifndef _HERBE
    #define _HERBE
     
     
    struct Herbe{
                 int X;
                 int Y;
                 int nbFoxMale;
                 int nbFoxFemelle;    
                 int nbRabbitMale;
                 int nbRabbitFemelle;
                 int hauteurHerbe;
                 };
     
     
     
    #endif
    Monde.h:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
     
    #ifndef _MONDE
    #define _MONDE
     
    #include "./Herbe.h"
    #include "./Para.h"
    #include <vector>
    using namespace std;
     
    #define TailleMonde tabInfo[0]
     
    typedef vector<Herbe> VecHerbe;
     
    class Monde:private VecHerbe
    {
    public:
    Monde():VecHerbe()
    { //création du VecHerbe avec le taille du monde en paramètre          
            for(int j=0;j<TailleMonde;j++)
                    {
                     for(int k=0;k<TailleMonde;k++)
                             {
                              Herbe h;
                              h.X=k;
                              h.Y=j;
                              h.nbFoxMale=0;
                              h.nbFoxFemelle=0;    
                              h.nbRabbitMale=0;
                              h.nbRabbitFemelle=0;
                              h.hauteurHerbe=(rand()%tabInfo[5])+(tabInfo[6]-tabInfo[5]);//compris entre min et max de l'Herbe
                              this->push_back(h);                     
                             }                      
                    }
      }
    ~Monde()
            {
             this->clear();        
            }                
    Herbe & operator[](int i)//retourne la ieme instance de Herbe contenue dans le VecHerbe
      {
       return *(begin()+i);                        
      }          
    int getSize(){return this->size();} //retourne le taille du VecHerbe 
    void rapportGlobal()//permet d'effectuer un rapport global sur le monde grace à tabRapport
    {
      for (int i =0; i != this->getSize(); ++i)
          {
           tabRapport[0]+= this->operator[](i).nbRabbitFemelle;//nb total de femrabbit                   
           tabRapport[1]+= this->operator[](i).nbRabbitMale;//nb total de malrabbit
           tabRapport[2]+= this->operator[](i).nbFoxFemelle;//nb total de femfox
           tabRapport[3]+= this->operator[](i).nbFoxMale;//nb total de malfox
           tabRapport[4]+= this->operator[](i).hauteurHerbe;//hauteur totale dans le monde
          }     
     
      tabRapport[5]=tabRapport[0]+tabRapport[1]-tabRapport[9];//nb tot de rabbit
      tabRapport[6]=tabRapport[2]+tabRapport[3]-tabRapport[10];//nb tot de fox
    }  
    Herbe & getCase(int x,int y)//retourne l'instance d'Herbe de coordonnés x,y
           {
            return this->operator[](y*tabInfo[0]+x);              
           } 
    Herbe * getPtrCase(int x,int y)
           {
            return &this->operator[](y*tabInfo[0]+x);              
           } 
    void rapportCase(int x,int y)//rapport spécifique à une case de coordonnés x,y
          {
           Herbe h=this->getCase(x,y);
           tabCase[0]=h.X; 
           tabCase[1]=h.Y; 
           tabCase[2]=h.nbFoxMale; 
           tabCase[3]=h.nbFoxFemelle;
           tabCase[4]=h.nbRabbitMale;
           tabCase[5]=h.nbRabbitFemelle;
           tabCase[6]=h.hauteurHerbe;
          }
     void finDeTour()
          {
           for(int j=0;j<TailleMonde;j++)
                    {
                     for(int k=0;k<TailleMonde;k++)
                             {
                              this->getCase(k,j).hauteurHerbe+=tabInfo[7];
                              if(this->getCase(k,j).hauteurHerbe>tabInfo[6])this->getCase(k,j).hauteurHerbe=tabInfo[6];
                             }                      
                    } 
           //reinitialiser le tabRapport pour un nouveau tour
           tabRapport[4]=0;    
           tabRapport[7]=0;
           tabRapport[8]=0;
           tabRapport[9]=0;
           tabRapport[10]=0;
           tabRapport[11]=0;           
          }
    };
     
    #endif
    et enfin para.h

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
     
    #ifndef _PARA
    #define _PARA
     
    // Tableau des paramètres d'initialisation
    int tabInfo[22];
     
    //Tableau pour rapport particulier à une case
    int tabCase[7]={0,0,0,0,0,0,0};
    //chaque indice correspond au attributs de la struct Herbe
     
    //Tableau pour le rapport de fin de tour
    int tabRapport[12]={0,0,0,0,0,0,0,0,0,0,0,0};
     
    /*
    0=nb total de femrabbit  
    1=nb total de malrabbit     
    2=nb total de femfox         
    3=nb total de malfox         
    4=hauteur totale dans le monde  
    5=nb tot de rabbit=tabRapport[0]+tabRapport[1]-tabRapport[9]    
    6=nb tot de fox=tabRapport[2]+tabRapport[3]-tabRapport[10]      
    7=nb naiss de rabbit // dans se reproduire pour rabbit     
    8=nb naiss de fox // dans se reproduire pour Fox        
    9=nb dead rabbit //dans manger pour Renard age>age max (fin tour)             
    10=nb dead fox //dans manger (suralim) age>age max (fin tour)      
    11=hauteur d'herbe mangée //dans manger pour Lapin
    */
     
     
     
    // Procédure d'initialisation du tableau des donnée statiques.
    void initTabInfo(
    int tailleMonde,
    int ageMaxRabbit,
    int ageMaxFox,
    int nrjMaxRabbit,
    int nrjMaxFox,
    int hauteurMinHerbe,
    int hauteurMaxHerbe,
    int croissanceHerbe,
    int nbCouple
    )
    {
      tabInfo[0]= tailleMonde;
      tabInfo[1]= ageMaxRabbit;
      tabInfo[2]= ageMaxFox;
      tabInfo[3]= nrjMaxRabbit;
      tabInfo[4]= nrjMaxFox;  
      tabInfo[5]= hauteurMinHerbe;
      tabInfo[6]= hauteurMaxHerbe;
      tabInfo[7]= croissanceHerbe; 
      tabInfo[8]= tabInfo[6]/10;//qte_eat_lap
      tabInfo[9]= tabInfo[3]/2;//nrj_birth_rabbit,
      tabInfo[10]= tabInfo[4]/2;//nrj_birth_fox, 
      tabInfo[11]= tabInfo[3]/5;// nrj_mini_move_rabbit,
      tabInfo[12]= tabInfo[4]/5;// nrj_mini_move_fox,
      tabInfo[13]= tabInfo[3]/5;//nrj_spent_reprod_rabbit
      tabInfo[14]= tabInfo[4]/3;//nrj_spent_reprod_fox,
      tabInfo[15]= tabInfo[1]/8;// age_min_reprod_rabbit,
      tabInfo[16]= tabInfo[2]/6;// age_min_reprod_fox,
      tabInfo[17]= tabInfo[3]/10;// nrj_eat_lap,
      tabInfo[18]= tabInfo[4]/10;// nrj_eat_fox,
      tabInfo[19]= tabInfo[3]/20;// nrj_mov_lap,
      tabInfo[20]= tabInfo[4]/10;// nrj_mov_fox,
      tabInfo[21]=nbCouple;
    }
     
     
    #endif
    Le main.cpp et les erreurs qu'il produit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
     
    #include <iostream>
    using namespace std;
    #include "./Para.h"
    #include "./Monde.h"
    #include "./Faune.h"
     
     
    int main()
    {/*
    cout<<"Bonjour Yo et Bert"<<endl;
    initTabInfo(10,25,25,100,100,20,100,10,10);
    for(int i=0;i<22;i++)cout<<i<<": "<<tabInfo[i]<<"\t";
    cout<<endl;
     
     
     
    m.rapportGlobal();
    cout<<"rapportglobal\n";
    for(int i=0;i<11;i++)cout<<m(i)<<"\t";
    */
     
    Herbe h;
     
    h.hauteurHerbe = 0;
    h.nbFoxFemelle = 0;
    h.nbFoxMale = 0;
    h.nbRabbitFemelle = 0;
    h.nbRabbitMale = 0;
    h.X = 12;
    h.Y = 14;
     
    Herbe* ph = &h;
     
    Faune f;
     
     
    Renard *r = new Renard();
     
     
    r->setPos(ph);
     
    f.addAnimal(r);
     
     
    cout<<endl<<r->getRef();
     
     
     
     
     
     
     
    return 0;
    }
    Les erreurs de compilo :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     undefined reference to `Renard::Renard()'
     undefined reference to `Animal::setPos(Herbe*)'
     undefined reference to `Animal::getRef()'
    Faune::addAnimal(Animal*)':
     undefined reference to `Animal::getType()'
    Faune::addAnimal(Animal*)':
    undefined reference to `Animal::getSex()'
    `Faune::addAnimal(Animal*)':
    undefined reference to `Animal::getPos()'
    ...
    voila tout j'avoue que je suis un peu dépassé
    merci à vous !

  9. #9
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    1. Pas de using namespace dans un .h (monde.h)
    2. Pas de définition de fonction dans un .h, à moins qu'elle soit déclarée inline (para.h)
    3. Pas d'instanciation de variables globales dans un .h : Seulement des déclarations avec le modificateur extern (para.h)
    4. Pas de using namespace avant d'avoir inclus tous les headers (main.cpp)
    5. Tes erreurs sont des erreurs à l'édition de liens: Elles signifient que certaines fonctions sont déclarées mais définies nulle part.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  10. #10
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 42
    Points : 28
    Points
    28
    Par défaut
    merci pour votre aide ça m'a permis d'apprendre des choses, g trouvé d'où venait l'erreur de linkage, enfin plutot on a refait le makefile, pour gérer les dépendance et les .cpp

    en tout cas merci à vous

    ps: si le projet marche bien je le posterais o moins que vous mettiez quelques choses derrières c'est quelques lignes de codes

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 7
    Dernier message: 22/07/2009, 10h20
  2. Problème avec ie (et oui encore)
    Par Fabious dans le forum Webdesign & Ergonomie
    Réponses: 1
    Dernier message: 29/01/2008, 15h32
  3. Réponses: 22
    Dernier message: 22/01/2007, 21h09
  4. Problème d'inclusion de pages.
    Par julien85 dans le forum XML/XSL et SOAP
    Réponses: 6
    Dernier message: 01/05/2005, 18h06
  5. Problème d'inclusion
    Par degreste dans le forum MFC
    Réponses: 5
    Dernier message: 27/01/2004, 00h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo