Bag ADT : Abstract Data Types in C++ – 5

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)


Bag answer;

assert (b1.size ( ) + b2.size ( ) <= CAPACITY);

answer += b1;

answer += b2;




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: