(Assuming not an abstract class and a class for integers or something) |
But it is an abstract class, the functions are pure virtual (because of the
= 0
at the end), so it needs to be over ridden in a derived class. If any function is pure virtual, then it's an abstract class. And one specifically cannot create an instance of
Item
The class does need a virtual destructor as well, whenever there are virtual functions you need a virtual destructor.
The idea of returning a pointer to the base class is probably meant to achieve polymorphism - have a read in the tutorial at the top left of this page - it explains it well :+)
It has nothing to do with constructors, the name of the function is
add
, whereas the class name is
Item
.
Avoid using
new
and
delete
, use RAII with smart pointers instead. Read up about that also :+)
There is some really good reading here, by The inventor of C++ Bjarne Stroustrup, and Herb Sutter:
Thanks to
MiiNiPaa for posting that, it was awesome :+D