Boujours,

Après avoir passé beaucoup de temps à chercher la solution, j'en appel à vôtre aide :

Je ne comprend pas pourquoi la compilation plante lorsque je veux utiliser une clé de type complex dans un map!

Voici un bout de code reproduisant le problème :
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
#include <string>
#include <map>
#include <list>
#include <complex>
#include <iostream>
 
using namespace std;
 
int main ( int argc, char *argv[] ) {
 
	typedef string		 action;
	typedef complex<int> state;	//PROBLEME avec le type complex !!!!
	//typedef string state;	//Compilation OK en remplaçant complex<int> par string
	//typedef int state;	//Compilation OK en remplaçant complex<int> par int
 
	map< state, action > monMap;
	action mouvement = "azerty";
	state etat = complex<int>(-1,-1);	//PROBLEME avec le type complex !!!!
	//state etat = "coucou";//Compilation OK en remplaçant complex<int> par string
	//state etat = 2;	//Compilation OK en remplaçant complex<int> par int
 
	monMap[etat] = mouvement;
}
Ce code ne compile pas si le typedef state est du type complex alors qu'il compile sans problèmes avec d'autre types ( j'ai essayé en mettant string ou int ) ( Le compilateur utilisé est VS2008 )

Voici ce que me raconte le compilateur :

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
------ Build started: Project: Fourre_Tout_Console, Configuration: Debug Win32 ------
Compiling...
Fourre_Tout_Console.cpp
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\list(1310) : see declaration of 'std::operator <'
        d:\program files\microsoft visual studio 9.0\vc\include\functional(142) : while compiling class template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const'
        with
        [
            _Ty=state
        ]
        d:\program files\microsoft visual studio 9.0\vc\include\map(68) : see reference to class template instantiation 'std::less<_Ty>' being compiled
        with
        [
            _Ty=state
        ]
        d:\program files\microsoft visual studio 9.0\vc\include\xtree(22) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled
        with
        [
            _Kty=state,
            _Ty=action,
            _Pr=std::less<state>,
            _Alloc=std::allocator<std::pair<const state,action>>,
            _Mfl=false
        ]
        d:\program files\microsoft visual studio 9.0\vc\include\xtree(63) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
        with
        [
            _Traits=std::_Tmap_traits<state,action,std::less<state>,std::allocator<std::pair<const state,action>>,false>
        ]
        d:\program files\microsoft visual studio 9.0\vc\include\xtree(89) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled
        with
        [
            _Traits=std::_Tmap_traits<state,action,std::less<state>,std::allocator<std::pair<const state,action>>,false>
        ]
        d:\program files\microsoft visual studio 9.0\vc\include\xtree(107) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
        with
        [
            _Traits=std::_Tmap_traits<state,action,std::less<state>,std::allocator<std::pair<const state,action>>,false>
        ]
        d:\program files\microsoft visual studio 9.0\vc\include\map(78) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
        with
        [
            _Traits=std::_Tmap_traits<state,action,std::less<state>,std::allocator<std::pair<const state,action>>,false>
        ]
        d:\visual studio 2010\projects\fourre_tout_console\fourre_tout_console\fourre_tout_console.cpp(16) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
        with
        [
            _Kty=state,
            _Ty=action
        ]
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\list(1310) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\list(1310) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\xtree(1466) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\xtree(1466) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\xtree(1466) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\string(150) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\string(150) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\string(150) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\string(140) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\string(130) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\string(130) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\string(130) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\xutility(2236) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\xutility(2236) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\xutility(2236) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\xutility(2046) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\xutility(2046) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\xutility(2046) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\utility(84) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\utility(84) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const state'
        d:\program files\microsoft visual studio 9.0\vc\include\utility(84) : see declaration of 'std::operator <'
d:\program files\microsoft visual studio 9.0\vc\include\functional(143) : error C2676: binary '<' : 'const state' does not define this operator or a conversion to a type acceptable to the predefined operator
Build log was saved at "file://d:\visual studio 2010\Projects\Fourre_Tout_Console\Fourre_Tout_Console\Debug\BuildLog.htm"
Fourre_Tout_Console - 23 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========