Bag ADT : Abstract Data Types in C++ – 5
February 13, 2011 Leave a comment
We discuss here the overloaded + operator, which is a non-member function.
Bag operator + ( const Bag& b1, const Bag& b2);
The + operator returns a Bag instance contains the union of the Items contained in b1 and b2. (Note that this may result in multiple copies of some Items.)
The function performs the union only if the combined sizes of the 2 instances is at moat CAPACITY.
Bag operator + (const Bag& b1, const Bag& b2)
assert (b1.size ( ) + b2.size ( ) <= CAPACITY);
answer += b1;
answer += b2;