Hi, i have a base class called Item which contains subclasses, Book, Serial and Newspaper. I have a virtual function called dispInfo which will display the information for that particular type of item. I have another function called GetItem(&Item), which searches through a list of Items for the one with a particular title. This returns a pointer to an Item. My question is how can i use this pointer as a Book, Serial or Newspaper instead of an item. I have something like this, but it always returns an Item.
[tag]
[/tag]Code:Item* ItemListNode::GetItem(Item &anItem) { if(FindItem(anItem)) //increases the iterator until found { return &*position; //position is a list iterator } return NULL; }
Meanwhile...in main()
[tag]
[/tag]Code:Book*aBook=NULL; anItem=ItemDatabase.GetItem(newBook); anItem.disInfo();
The output is: "I AM AN ITEM!" instead of "I AM A BOOK!"
Can someone please help!?



LinkBack URL
About LinkBacks


