Bonjour, je souhaite créer une classe "vector" pour la programmation d'un arduino. En effet, je n'ai pas pu inclure dans mon projet les fichiers STL qui me permette d'utiliser cette classe. J'ai quelques erreurs dans mon code et je voudrais de l'aide pour les corriger. Merci
MyVector.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 * /* fichier MyVector.h */ #include <iostream> using namespace std; template<typename ItemType> class MyVector { public: MyVector(); MyVector(int max_size_input); ~MyVector(); void push_back(ItemType& element_to_add); void pop_back(); int getSize(); ItemType operator[](int i); private: int vect_size; int max_size; ItemType* array; }
MyVector.cpp
Les erreurs renvoyées après compilation:
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 /* fichier */ #include <iostream> #include "MyVector.h"; //using namespace std; template<typename ItemType> MyVector::MyVector() { vect_size = 0; max_size = 5; array = new ItemType[max_size]; //assign pointer to new } MyVector::MyVector(int max_size_input) { vect_size = 0; max_size = max_size_input; array = new ItemType[max_size]; //assign pointer to new } MyVector::~MyVector() { //dealocate the memory delete[] array; } void MyVector:: push_back(ItemType& element_to_add) { array[vect_size] = element_to_add; vect_size++; } void MyVector:: pop_back() { vect_size--; } int MyVector:: getSize() { return vect_size; } ItemType MyVector:: operator[](int i) { return array[i]; }
MyVector.cpp:6: error: expected unqualified-id before 'template'
MyVector.cpp:14: error: 'template<class ItemType> class MyVector' used without template parameters
MyVector.cpp:14: error: ISO C++ forbids declaration of 'MyVector' with no type
MyVector.cpp:In function 'int MyVector(int)'
MyVector.cpp:14: error: 'int MyVector(int)' redeclared as different kind of symbol
MyVector.h:7: error: previous declaration of 'template<class ItemType> class MyVector'
MyVector.cpp:16: error: 'vect_size' was not declared in this scope
MyVector.cpp:17: error: 'max_size' was not declared in this scope
MyVector.cpp:18: error: 'array' was not declared in this scope
MyVector.cpp:18: error: expected type-specifier before 'ItemType'
MyVector.cpp:18: error: expected `;' before 'ItemType'
MyVector.cpp:At global scope
MyVector.cpp:21: error: expected constructor, destructor, or type conversion before '::' token
MyVector.cpp:27: error: 'template<class ItemType> class MyVector' used without template parameters
MyVector.cpp:27: error: variable or field 'push_back' declared void
MyVector.cpp:27: error: 'ItemType' was not declared in this scope
MyVector.cpp:27: error: 'element_to_add' was not declared in this scope
MyVector.cpp:34: error: 'template<class ItemType> class MyVector' used without template parameters
MyVector.cpp:In function 'void pop_back()'
MyVector.cpp:36: error: 'vect_size' was not declared in this scope
MyVector.cpp:At global scope
MyVector.cpp:39: error: 'template<class ItemType> class MyVector' used without template parameters
MyVector.cpp:In function 'int getSize()'
MyVector.cpp:41: error: 'vect_size' was not declared in this scope
MyVector.cpp:At global scope
MyVector.cpp:44: error: 'ItemType' does not name a type
Partager