Bonjour,
le code est à la fin
ça marche avec Visual C++ 6 et pas avec gcc 3.4.2, désolé j'ai essayé de comprendre avec les header "stl_vector.h" ...etc , mais je suis largué
//////////
Messages d'erreur de gcc:
/g++.exe -c src/main.cpp -o src/main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
src/main.cpp:12: error: expected `;' before "iter"
src/main.cpp: In member function `T papa<T>::prems()':
src/main.cpp:19: error: `iter' undeclared (first use this function)
src/main.cpp:19: error: (Each undeclared identifier is reported only once for each function it appears in.)
src/main.cpp: In member function `T fils<T>::premier()':
src/main.cpp:34: error: expected `;' before "iter"
src/main.cpp:35: error: `iter' undeclared (first use this function)
src/main.cpp: In member function `T fils<T>::premier() [with T = int]':
src/main.cpp:46: instantiated from here
src/main.cpp:34: error: dependent-name ` std::vector<T,std::allocator<_CharT> >::iterator' is parsed as a non-type, but instantiation yields a type
src/main.cpp:34: note: say `typename std::vector<T,std::allocator<_CharT> >::iterator' if a type is meant/
Code :
- ////// CODE
- #include <cstdlib>
- #include <iostream>
- #include <vector>
- #include <iterator>
- using namespace std;
- ////// CLASS PAPA ////////////////////////////////////////////
- template <class T> class papa {
-
- protected:
- std::vector<T> liste;
- std::vector<T>::iterator iter;
- public:
- inline void add (T elem) {
- liste.push_back(elem);
- };
- inline T prems () {
- iter = liste.begin();
- return *iter;
- };
- };
- //template <class T> papa::papa(T elem) {
- // liste.push_back(elem);
- ////// CLASS FILS ////////////////////////////////////////////
- template <class T> class fils : public papa <T> {
- public:
-
- inline T premier () {
- std::vector<T>::iterator iter = papa<T>::liste.begin();
- return *iter;
- };
- };
- //// MAIN //////////////////////////////////////////////
- int main(int argc, char *argv[])
- {
- papa<int> pere;
- fils<int> gars;
- pere.add(45);
- gars.add(12);
- cout << (int) pere.prems() << endl;
- cout << (int) gars.premier() << endl;
- cout << (int) gars.prems() << endl;
- system("PAUSE" );
- return 0;
- }
|
Message édité par gilles_paca_aix le 06-04-2005 à 12:19:10