Bonjour!

J'ai programmé pas mal en Java et j'essai de retranscrire une application java en C++ (je connais le C++ j'en ai fait longtemps mais j'ai arrété).

J'ai un problème, je ne sais pas du tout pourquoi.

J'utilise une enumeration comme clé dans une map et ça ne plait pas au compilateur ^^

Enfin un exemple vaut mieux qu'un long discours.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
#include <map>
 
enum class Test{
    T1,
    T2
};
 
int main ( int argc, char** argv ){
    std::map<Test,float> t_map;
    Test e = Test::T1;
    float s = t_map[e];
}
Voici l'erreur:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
(x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_function.h||In member function 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Test]':|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_map.h|449|instantiated from '_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = Test, _Tp = float, _Compare = std::less<Test>, _Alloc = std::allocator<std::pair<const Test, float> >]'|
C:\Users\Cedric\ProgrammesC++\GAME\main.cpp|20|instantiated from here|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_function.h|230|error: invalid operands of types 'const Test' and 'const Test' to binary 'operator<'|
||=== Build finished: 1 errors, 1 warnings (0 minutes, 22 seconds) ===|
Merci beaucoup pour vos réponse