Bonsoir,

Je débute complètement Boost ( j'ai commencé a y toucher avant-hier), je suis un peu perdu dans tout ces concepts de graph mais bon, je fais avec.

Mon objectif est de créer un graph de type undirected avec des vertex comportant plusieurs propriétés.

J'ai commencé par faire un truc qui marche : un pays possède un nom ( en String)

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
 
#include <boost/config.hpp>
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost\property_map\property_map.hpp>
using namespace std;
using namespace boost;
 
struct name_tag { 
	typedef vertex_property_tag kind;
};
typedef boost::property<name_tag,std::string> NameProperty;
 
typedef boost::adjacency_list<boost::listS,boost::vecS,boost::undirectedS,NameProperty> Graph;
 
int main(){
	Graph g;
	property_map<Graph,name_tag>::type
		name = get(name_tag(), g);
 
	boost::graph_traits < Graph >::vertex_descriptor A, B, C, D;
 
 
	A = boost::vertex(0,g);
	B = boost::vertex(1,g);
	C = boost::vertex(2,g);
	D = boost::vertex(3,g);
 
	boost::add_edge(A, B, g);
	boost::add_edge(B, C, g);
	boost::add_edge(C, D, g);
	boost::add_edge(D, A, g);
 
	boost:put(name,A,"France");
	name[B] = "Mongolie";
	name[C] = "Zanzibar";
	name[D] = "Costa Rica";
 
	cout << name[C];
	cin >> name[D];
	return 0;
Mais, étant de nature exigeante je veux un nom ET une population, j'ai encapsulé le tout dans une class, ça m'a semblé tout naturel mais mon compilateur ne possède pas le même point de vue.
Voila ce que j'ai écrit :

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
 
#include <boost/config.hpp>
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost\property_map\property_map.hpp>
 
 
using namespace std;
using namespace boost;
 
class pays{
	public:
	string nom;
	int population;
	pays(string nom_E,int population_E): nom(nom_E) , population(population_E) {}
};
 
struct pays_tag { 
	typedef vertex_property_tag kind;
};
typedef boost::property<pays_tag,pays> PaysProperty;
 
typedef boost::adjacency_list<boost::listS,boost::vecS,boost::undirectedS,PaysProperty> Graph;
 
 
int main(){
	pays France("France",42);
 
	Graph g;
	property_map<Graph,pays_tag>::type
		pays = get(pays_tag(), g);
 
	boost::graph_traits < Graph >::vertex_descriptor A, B, C, D;
 
 
	A = boost::vertex(0,g);
	B = boost::vertex(1,g);
	C = boost::vertex(2,g);
	D = boost::vertex(3,g);
 
	boost::add_edge(A, B, g);
	boost::add_edge(B, C, g);
	boost::add_edge(C, D, g);
	boost::add_edge(D, A, g);
 
	pays[0]= France;
 
	cout << pays[0].nom << "\t" << pays[0].population;
 
	return 0;
 
}
Experts en Boost, auriez vous des réponses à ce problème ?
Merci d'avance et bonne soirée !