hi all , I have writen a set.h file ! but I keep receiving these errors :
Set.h: In member function ‘void Set<T>::add(const T&)’:
Set.h:29: error: expected ‘;’ before ‘result’
Set.h:33: error: ‘result’ was not declared in this scope
Set.h: In member function ‘void Set<T>::remove(const T&)’:
Set.h:55: error: expected ‘;’ before ‘it’
Set.h:57: error: ‘it’ was not declared in this scope
Set.h: In member function ‘bool Set<T>::exists(const T&) const’:
Set.h:83: error: expected ‘;’ before ‘result’
Set.h:85: error: ‘result’ was not declared in this scope
can anybody help me solve it?
my code is :
Code://Jeren AKHOUNDI (1836345) Homework2 set.h #ifndef __SET_H__ #define __SET_H__ using namespace std; #include <iostream> #include <vector> #include <algorithm> #include "SetException.h" template <class T> class Set { private: vector<T> v; public: // ADD ================================================================================== void add (const T& x) { vector<T>::iterator result; //try //{ result = find (v.begin(), v.end(), x); if (result != v.end()) { throw SetException(ITEM_ALREADY_EXISTS,"item already exists"); } //} //catch (SetException& exc) //{ //exc.what(); //} v.push_back(x); } // REMOVE =============================================================================== void remove (const T& x) { vector<T>::iterator it; it = search (v.begin(), v.end(), x); //try //{ if (it == v.end()) throw SetException(ITEM_NOT_EXISTS,"item not exists"); //catch (SetException& exc) //{ //exc.what(); //} else { int def = it - v.begin(); v.erase(v.begin() + def ); } } // EXISTS =============================================================================== bool exists(const T& item)const { vector<T>::iterator result; result = find (v.begin() , v.end(), item); if (result != v.end) return true; else return false; } // CARDINALITY =========================================================================== int cardinality()const { return v.size(); //int result; //for (int i=0; i<v.end(); i++) //{ //result = v.count(i); //} //return result; } }; // end of class #endif



1Likes
LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.