Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <functional>
- List * prescriptions; // List is a test header, but ihats not where the problem is
- using cb_prescription = std::function<void(Prescription * prescription)>;
- void loop_prescriptions (cb_prescription callback, bool add);
- int main ()
- {
- char * name = new char[6];
- strcpy(name, "abcdef");
- prescriptions = new List(Sorted); //creates an empty list, but lets say there are some elements
- Prescription * paper = new Prescription(); //has method hasPatient, which compares to char arrays and returns boolean
- loop_prescriptions ([&] (Prescription * paper) { //and somewhere in here
- if (paper->hasPatient(name)) {
- paper->display();
- }
- });
- return 0;
- }
- void loop_prescriptions (cb_prescription callback, bool add = true)
- {
- //loop through all the elements
- for (int i = 1; i <= prescriptions->noOfElements(); i++) {
- //get the element and send it to callback for usage
- Prescription * prescription = (Prescription *) prescriptions->removeNo(i); //removeNo, returns a pointer to the prescription class (Prescription *)
- if (add) { //since the element has been removed, it should be readded unless the developer says so
- prescriptions->add(prescription);
- }
- callback(prescription); //return the element
- }
- }
Add Comment
Please, Sign In to add comment