I'm reading a book called Beginning Algorithms by Harris and Ross, which gives code examples in Java. As an academic exercise I am trying to convert the code examples to C++. In the interface below the part that throws me is the return of the 'Object' by the 'current' method.
Java
public interface Iterator {
public void first();
public void last();
public boolean isDone();
public void next();
public void previous();
public Object current() throws IteratorOutOfBoundsException;
}
I have turned this into the following abstract class. In particular I would like to know if my use of the template function is the best way of solving the return of the the unknown object.
C++
class Iterator
{
public:
virtual void first()=0;
virtual void last()=0;
virtual bool isDone()=0;
virtual void next()=0;
virtual void previous()=0;
template <typename V>
V current();
};