Rebonjour

Suit à mon sujet précédent, j'ai toujours une satanée erreur du à une insertion d'un objet dans un vecteur. Je vous poste mon code et je vous explique après.

Contrainte.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
 
#include <iostream>
#include "Contrainte.h"
#include "Recherche.h"
 
using namespace std;
 
Contrainte::Contrainte ( Recherche* recherche , int niv )
{
	objet = recherche ;
	niveau = niv ;
}
 
bool Contrainte::isValide ()
{
	return ( (*objet).getNiveau() >= niveau );
}
Contrainte.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
 
#ifndef CONTRAINTE_H
#define CONTRAINTE_H
 
class Recherche;
 
class Contrainte
{
	private:
 
	Recherche* objet ;
	int niveau ;
 
	public:
 
	Contrainte ( Recherche* recherche , int niv );
	bool isValide();
};
 
#endif
Recherche.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
 
#include <iostream>
#include <vector>
#include <string>
#include "Contrainte.h"
#include "Recherche.h"
 
using namespace std;
 
Recherche::Recherche( std::string NOM , int GID , int METAL , int CRISTAL , int DEUT )
{
	nom = NOM ;
	gid = GID ;
	metal = METAL ;
	cristal = CRISTAL ;
	deuterium = DEUT ;
	niveau = 0 ;
}
 
int Recherche::getNiveau()
{
	return niveau ;
}
 
void Recherche::setNiveau( int niv )
{
	niveau = niv ;
}
 
void Recherche::addContrainte ( Recherche* objet , int niv )
{
	contraintes.push_back( Contrainte( objet , niv ) );
}
Recherche.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
 
#ifndef RECHERCHE_H
#define RECHERCHE_H
 
#include <vector>
#include <string>
#include "Contrainte.h"
 
 
class Recherche
{
	private:
 
	std::string nom ;
	int gid ;
	int metal ;
	int cristal ;
	int deuterium ;
	int niveau ;
	std::vector<Contrainte> contraintes ;
 
	public:
 
	Recherche( std::string NOM , int GID , int METAL , int CRISTAL , int DEUT );
	int getNiveau ();
	void setNiveau ( int niv );
	void addContrainte ( Recherche* objet , int niv );
};
 
#endif
Donc chaque Recherche possède des contraintes avant sa construction ( dont on ne connait pas le nombre) et chaque contrainte pointe sur un batiment existant.

Le problème provient (d'après mon interprétation du message d'erreur) de l'ajout d'une contrainte. Je vous donne mon message d'erreur

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
 
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main'
/tmp/ccz9mBVk.o: In function `__static_initialization_and_destruction_0(int, int)':
Contrainte.cpp:(.text+0x69): undefined reference to `std::ios_base::Init::Init()'
Contrainte.cpp:(.text+0x6e): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccz9mBVk.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
/tmp/ccw6kYOE.o: In function `Recherche::Recherche(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int, int, int)':
Recherche.cpp:(.text+0xf): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
Recherche.cpp:(.text+0x2f): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
Recherche.cpp:(.text+0x8b): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccw6kYOE.o: In function `Recherche::Recherche(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int, int, int)':
Recherche.cpp:(.text+0xab): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
Recherche.cpp:(.text+0xcb): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
Recherche.cpp:(.text+0x127): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccw6kYOE.o: In function `__static_initialization_and_destruction_0(int, int)':
Recherche.cpp:(.text+0x1a5): undefined reference to `std::ios_base::Init::Init()'
Recherche.cpp:(.text+0x1aa): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccw6kYOE.o: In function `std::vector<Contrainte, std::allocator<Contrainte> >::_M_insert_aux(__gnu_cxx::__normal_iterator<Contrainte*, std::vector<Contrainte, std::allocator<Contrainte> > >, Contrainte const&)':
Recherche.cpp:(.text._ZNSt6vectorI10ContrainteSaIS0_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS0_S2_EERKS0_[std::vector<Contrainte, std::allocator<Contrainte> >::_M_insert_aux(__gnu_cxx::__normal_iterator<Contrainte*, std::vector<Contrainte, std::allocator<Contrainte> > >, Contrainte const&)]+0x227): undefined reference to `__cxa_begin_catch'
Recherche.cpp:(.text._ZNSt6vectorI10ContrainteSaIS0_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS0_S2_EERKS0_[std::vector<Contrainte, std::allocator<Contrainte> >::_M_insert_aux(__gnu_cxx::__normal_iterator<Contrainte*, std::vector<Contrainte, std::allocator<Contrainte> > >, Contrainte const&)]+0x288): undefined reference to `__cxa_rethrow'
Recherche.cpp:(.text._ZNSt6vectorI10ContrainteSaIS0_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS0_S2_EERKS0_[std::vector<Contrainte, std::allocator<Contrainte> >::_M_insert_aux(__gnu_cxx::__normal_iterator<Contrainte*, std::vector<Contrainte, std::allocator<Contrainte> > >, Contrainte const&)]+0x291): undefined reference to `__cxa_end_catch'
/tmp/ccw6kYOE.o: In function `std::vector<Contrainte, std::allocator<Contrainte> >::_M_check_len(unsigned int, char const*) const':
Recherche.cpp:(.text._ZNKSt6vectorI10ContrainteSaIS0_EE12_M_check_lenEjPKc[std::vector<Contrainte, std::allocator<Contrainte> >::_M_check_len(unsigned int, char const*) const]+0x36): undefined reference to `std::__throw_length_error(char const*)'
/tmp/ccw6kYOE.o: In function `__gnu_cxx::new_allocator<Contrainte>::deallocate(Contrainte*, unsigned int)':
Recherche.cpp:(.text._ZN9__gnu_cxx13new_allocatorI10ContrainteE10deallocateEPS1_j[__gnu_cxx::new_allocator<Contrainte>::deallocate(Contrainte*, unsigned int)]+0xd): undefined reference to `operator delete(void*)'
/tmp/ccw6kYOE.o: In function `__gnu_cxx::new_allocator<Contrainte>::allocate(unsigned int, void const*)':
Recherche.cpp:(.text._ZN9__gnu_cxx13new_allocatorI10ContrainteE8allocateEjPKv[__gnu_cxx::new_allocator<Contrainte>::allocate(unsigned int, void const*)]+0x24): undefined reference to `std::__throw_bad_alloc()'
Recherche.cpp:(.text._ZN9__gnu_cxx13new_allocatorI10ContrainteE8allocateEjPKv[__gnu_cxx::new_allocator<Contrainte>::allocate(unsigned int, void const*)]+0x32): undefined reference to `operator new(unsigned int)'
/tmp/ccw6kYOE.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
/tmp/ccw6kYOE.o:(.eh_frame+0x4b): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

PS : je compile en faisant gcc *.cpp