This code will build & run, but the last part of the main file, which executes a function, does not correctly use polymorphism.
Your task is to update bag/set/magicbag/bean .h and .cpp files so that polymorphism works, and the main file gives the desired output.
JellyBag should be the parent class. The others are child classes of JellyBag. A JellyBag just holds JellyItems in no particular order. Repeats are allowed.
JellySet eliminates duplicate values.
JellyMagicBag is the same as JellyBag except when iterating through values (using
next()), the order is random.
JellyBean can only hold zero or one JellyItems, so adding a second item removes the first.
When you rewrite the classes, you must maximize the benefit of inheritance: do not write any extra code in the child classes that is not absolutely required. Call on your parent methods. Note, sometimes your child class will define a method like
add() that must call the JellyBag version of
add(). To do so, you must write
JellyBag::add() in the child method because if you just write
add() then the child method will call itself infinitely.