A bonus advice to my answer (sorry I repeat myself, but this time I'll make in more clear).
You really, really need to get rid of
Error_code
. Here is how:
List_entry retrieve(int position) const
{
if (empty()) throw "underflow";
if (position<0 || position>count) throw "range error";
return entry[position];
}
This
throw
part is simplified, just for example. Instead of string, it should better be some class or different classes for different errors; for range error it should be initialized with valid range and actual value of
position
.
The benefits of exceptions are so overwhelming, that the techniques which involve returning of error information makes no sense anymore, since structural exception handling was invented (for CLU language, circa 1970) by Barbara Liskov, a Turing Award laureate (2008).
Unfortunately, this is no time to explain all the techniques and the motivation, but there is a huge choice of literature on the topic. (I am not familiar with the introductory literature; I am one of the early implementors of the technology when it was not yet introduced in C++ -- believe or not.)