I'm doing a program that manages a collection of items. That can be a Book, a Magazine, a CD or a DVD. Each of those is a class thats inherits the class Item. To store those items I'm using the list template, like this:
list<Item> items;
and this list is inside an object lib of the class Library.
To run through this list I'm doing this:
for(list<Item>::iterator i = lib.itens.begin(); i != lib.itens.end(); ++i)
Until this point everything's fine. The problem starts when I try to call a method of the derived class inside this loop. example:
for(list<Item>::iterator i = lib.itens.begin(); i != lib.itens.end(); ++i)
(*i).lib.itens.show();
How can I call those methods?