Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STL and Inheritance

Status
Not open for further replies.

arunag

Programmer
Joined
Oct 3, 2001
Messages
4
Location
DE
I am using STL queue ie., std::queue<CData> DataQ.
and i am also using push(), pop(), front() of the queue.
My question is if i want to push or pop the queue objects of CDerivedData. Here CDerivedData is inherited from CData. Is this right thing??
Why i want this to do is in my queue i want to insert two kinds of objects..
or what would be the other method??
Aruna.
 
No this won't work. Your queue is storing CData objects, and if you assign a CDerivedData, the Derived bit will be sliced off. This is a C++ issue, not STL. You can store CData* in your queue, and then put a CDerivedData pointer there, that'll work. Generally speaking though it's not very efficient to store objects of any complexity themselves in a queue, there's a lot of copy constructors being called.
:-) I just can't help it, I like MS...:-)
 
use std::queue<CData*> and push/popsome new CDerivedData Ion Filipski
1c.bmp


filipski@excite.com
 
Yeah, like I said, but don't forget to delete them after you've popped them... :-) Click here if this helped! :-)
vvvvvvvvv
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top