so I have 5 classes,
- cds
- dvds
- books
- Item
- Inventory
My Item class is an abstract base class and cds,dvds, and books are derived from it. My Inventory class has an array of pointers of the Items type that point towards objects of cd,dvd, and books.
Here is the array:
Item* ptrItems[100];
int totalItems = 0`
Here is how assign an object to the array inside my Inventory class:
ptrItems[totalItems++] = new books(1000 + totalItems, quantity, tempTitle,tempAuthor, tempDesc, cost);
//I use total items as a counter to keep track of the index
The problem that i have is that ptrItems[totalItems] can not access the member functions of the derived classes only the member functions of the Items abstract class.
For example:
ptrItems[i]->getQuantity() //works fine because getQuanty is a member function of abstract base class Item.
however,
ptrItems[i]->getBookTile() // won't work
error C2039: 'getBookTile' : is not a member of 'Item'
Correct me if I'm wrong but isn't this polymorphism? It should have access to the derived classes public member functions, right?