hi,
ive made the following operator a friend because i need to access the private vector<int> set...but for some reason it gives me the following compile error
IntSet.h: In function `const IntSet operator+(const IntSet&, const IntSet&)':
IntSet.h:29: error: `std::vector<int, std::allocator<int> > IntSet::set' is
private
IntSet.cc:80: error: within this context
please note this is line 80:
Code:
for (constSetIterator it = b.set.begin(); it!=b.set.end(); ++it) {
..y?
Code:
/* returns a union of the sets a and b */
const IntSet operator+(const IntSet &a, const IntSet &b){
IntSet newSet = a;
for (constSetIterator it = b.set.begin(); it!=b.set.end(); ++it) {
if (!newSet.contains(*it))
newSet.add(*it);
}
return newSet;
}
its protoype in the .h file is
Code:
friend IntSet operator+(const IntSet a, const IntSet b);