hey,
im returning a begin() and end() iterator for my vector<int> in respective methods(including constBegin/End(), for some reason when i try to use it(ie. in contains()), the compiler gives errors. Also my copy constuctor gives a compile error, i dont understand why it says "error: parse error before `.' token"??
btw im new to c++ ...is that the correct way to use my copy constructor " IntSet newSet = a;"
thanks for any help
the method headers for the begin/end methods are hereCode:using namespace std; typedef vector<int>::iterator setIterator; typedef vector<int>::const_iterator constSetIterator; IntSet::IntSet(void) { } IntSet::IntSet(const IntSet&) { for (setIterator it = IntSet.begin(); it!=IntSet.end(); ++it) { this->add(*it); } } /* prints the entire set in accending order */ void IntSet::printSet(void)const { sort(constBegin(), constEnd()); for (constSetIterator it = constBegin(); it!=constEnd(); ++it) { cout << *it << ", "; } } /* returns true if v is in the set */ bool IntSet::contains(int v)const { for (constSetIterator it = constBegin(); it!=constEnd(); ++it) { if (v == *it) return true; } return false; } /* returns a union of the sets a and b */ IntSet operator+(IntSet a, IntSet b){ IntSet newSet = a; for (constSetIterator it = b.begin(); it!=b.end(); ++it) { if (!newSet.contains(*it)) newSet.add(*it); } return newSet; } setIterator IntSet::begin(void) { return this->set.begin(); } constSetIterator IntSet::constBegin(void) { return this->set.begin(); } setIterator IntSet::end(void) { return this->set.end(); } constSetIterator IntSet::constEnd(void) { return this->set.end(); }
Code:vector<int>::iterator begin(void); vector<int>::const_iterator constBegin(void); vector<int>::iterator end(void); vector<int>::const_iterator constEnd(void);



LinkBack URL
About LinkBacks


