Bonjour,
J'ai une erreur a propos des map de la STL. Je pense avoir bien manipule les maps. Mais des que je fais #include <map> ca fait des erreur de compile. Meme si je n'utilise pas les map... Voici le code j'espere que vous saviez d'ou vient l'erreur.
Os : Freebsd
Compilo : g++
ERROr :
Citation:
c++ -Wall -W -Werror -c main.cpp
In file included from /usr/include/c++/3.4/map:67,
from tree.hpp:8,
from main.cpp:4:
/usr/include/c++/3.4/bits/stl_map.h:121: error: expected `;' before '<' token
/usr/include/c++/3.4/bits/stl_map.h:124: error: `_Rep_type' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:133: error: `_Rep_type' has not been declared
/usr/include/c++/3.4/bits/stl_map.h:133: error: expected nested-name-specifier before "allocator_type"
/usr/include/c++/3.4/bits/stl_map.h:133: error: `allocator_type' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:134: error: `_Rep_type' has not been declared
/usr/include/c++/3.4/bits/stl_map.h:134: error: expected nested-name-specifier before "iterator"
/usr/include/c++/3.4/bits/stl_map.h:134: error: `iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:135: error: `_Rep_type' has not been declared
/usr/include/c++/3.4/bits/stl_map.h:135: error: expected nested-name-specifier before "const_iterator"
/usr/include/c++/3.4/bits/stl_map.h:135: error: `const_iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:136: error: `_Rep_type' has not been declared
/usr/include/c++/3.4/bits/stl_map.h:136: error: expected nested-name-specifier before "size_type"
/usr/include/c++/3.4/bits/stl_map.h:136: error: `size_type' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:137: error: `_Rep_type' has not been declared
/usr/include/c++/3.4/bits/stl_map.h:137: error: expected nested-name-specifier before "difference_type"
/usr/include/c++/3.4/bits/stl_map.h:137: error: `difference_type' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:138: error: `_Rep_type' has not been declared
/usr/include/c++/3.4/bits/stl_map.h:138: error: expected nested-name-specifier before "reverse_iterator"
/usr/include/c++/3.4/bits/stl_map.h:138: error: `reverse_iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:139: error: `_Rep_type' has not been declared
/usr/include/c++/3.4/bits/stl_map.h:139: error: expected nested-name-specifier before "const_reverse_iterator"
/usr/include/c++/3.4/bits/stl_map.h:139: error: `const_reverse_iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:155: error: expected `,' or `...' before '&' token
/usr/include/c++/3.4/bits/stl_map.h:195: error: expected `,' or `...' before '&' token
/usr/include/c++/3.4/bits/stl_map.h:223: error: `allocator_type' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:233: error: `iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:242: error: `const_iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:250: error: `iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:259: error: `const_iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:268: error: `reverse_iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:277: error: `const_reverse_iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:286: error: `reverse_iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:295: error: `const_reverse_iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:308: error: `size_type' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:313: error: `size_type' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:359: error: type/value mismatch at argument 1 in template parameter list for `template<class _T1, class _T2> struct std::pair'
/usr/include/c++/3.4/bits/stl_map.h:359: error: expected a type, got `iterator'
/usr/include/c++/3.4/bits/stl_map.h:382: error: `iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:409: error: variable or field `erase' declared void
/usr/include/c++/3.4/bits/stl_map.h:409: error: expected `;' before '(' token
/usr/include/c++/3.4/bits/stl_map.h:423: error: expected `;' before "size_type"
/usr/include/c++/3.4/bits/stl_map.h:423: error: `size_type' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:439: error: variable or field `erase' declared void
/usr/include/c++/3.4/bits/stl_map.h:439: error: expected `;' before '(' token
/usr/include/c++/3.4/bits/stl_map.h:453: error: expected `;' before "void"
/usr/include/c++/3.4/bits/stl_map.h:496: error: `iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:511: error: `const_iterator' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:523: error: `size_type' does not name a type
/usr/include/c++/3.4/bits/stl_map.h:538: error: `iterator' does not name a type
main.cpp
tree.hppCode:
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 #include <string> #include <iostream> #include "loadFile.hpp" #include "tree.hpp" int main(int argc, char *argv[]) { if (argc < 3) { std::cout << "Bad format !" << std::endl; return (EXIT_FAILURE); } loadDataFromFile *data = new loadDataFromFile(argv[1]); if (data->load()) { // data->dumpData(); Tree T; T.buildTree(data->getData()); } else { std::cout << "Could not get data from file" << std::endl; return (EXIT_FAILURE); } delete data; return (EXIT_SUCCESS); }
tree.cppCode:
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 #ifndef _TREE_H #define _TREE_H #include <iostream> #include <string> #include <vector> #include <list> #include <map> class Tree { public : Tree(); ~Tree(); void buildTree(std::vector<std::string>&); void stringtok(std::string&, std::vector<std::string>&, std::string&); private : std::map<int, std::list<double> > _tree; int _nb_states; }; #endif //_TREE_H
loadfile.hppCode:
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 #include <iostream> #include <string> #include <vector> #include <list> #include <map> #include <fstream> #include "tree.hpp" Tree::Tree() { } Tree::~Tree() { } void Tree::stringtok(std::string& str, std::vector<std::string> &tokens, std::string& delimiters) { std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); std::string::size_type pos = str.find_first_of(delimiters, lastPos); while (std::string::npos != pos || std::string::npos != lastPos) { tokens.push_back(str.substr(lastPos, pos - lastPos)); lastPos = str.find_first_not_of(delimiters, pos); pos = str.find_first_of(delimiters, lastPos); } } void Tree::buildTree(std::vector<std::string>& line) { std::vector<std::string>::iterator it; it = line.begin(); this->_nb_states = atoi((*it).c_str()); ++it; for (int i = 0; i < this->_nb_states; i++) { std::vector<std::string> listnode; std::string del(" "); this->stringtok((*it), listnode, del); std::list<double> tmp; for (int j = 0; j < this->_nb_states; j++) tmp.push_back(atof(listnode[j])); this->_tree[i] = tmp; ++it; }
Code:
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 #ifndef _LOADFILE_H #define _LOADFILE_H #include <iostream> #include <string> #include <vector> #include <fstream> class loadDataFromFile { public : loadDataFromFile(std::string); ~loadDataFromFile(); bool openFile(); void closeFile(); std::vector<std::string>& getData(); void loadData(); void dumpData(); bool load(); private : std::string _path; std::vector<std::string> _lines; std::ifstream _fd; }; #endif //_LOADFILE_H