list <helicopter> heliList; //list for helicopters
^this stl list to store objects of the type given above. Can anyone point me to snippets/examples where once on the list, the object has its details displayed, and used/played around with in general?
Obviously I'm asking for quite a specific thing, so I genuinely appreciate any input. Many thanks.
Rather than start a new thread, Ill try and stay in this one. I now need to use a user defined search criteria ( the serial number of the helicopter ) to find the object in the list and delete it.
I believe this involves overloading an operator? but that's far as it goes. Any ideas?
bool mySearchCriteria(const helicopter& heli)
{ return heli1.isApprovedByCIA(heli2); } // put whatever you use for your search ;)
...
list<helicopter>::iterator h = std::find_if ( heliList.begin(), heliList.end(), mySearchCriteria );
if ( h != heliList.end() )
{ // found a helicopter
helicopter helicopter = *h;
}
For uber-performance, try to look for "functors" (which are classes but called as if they were functions).
Ciao, Imi.
BTW: If your list is sorted, you can use a binary search. The uninformative named function "std::lower_bound" performs a binary search.
Am I right in thinking the above code could go straight into my search() function?
edit: the search function just has to locate the helicopter and cout its details, nothing more.
Sorry.
Think I may be confused. I'm trying to prompt the user for the serial, which is stored in a variable. Then if this number is found as a helicopters serial the details of that helicopter are printed. This isn't the right way of thinking is it?