Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. List * prescriptions; // List is a test header, but ihats not where the problem is
  2.  
  3. void loop_prescriptions ();
  4. typedef void (*cb_prescription)(Prescription * prescription); // the problem starts here
  5.  
  6. int main ()
  7. {
  8.   char * name = new char[6];
  9.   strcpy(name, "abcdef");
  10.  
  11.     prescriptions = new List(Sorted); //creates an empty list, but lets say there are some elements
  12.   Prescription * paper = new Prescription(); //has method hasPatient, which compares to char arrays and returns boolean
  13.  
  14.   loop_prescriptions ([&] (Prescription * paper) { //and somewhere in here
  15.     if (paper->hasPatient(name)) {
  16.         paper->display();
  17.     }
  18.   });
  19.  
  20.  
  21.   return 0;
  22. }
  23.  
  24.  
  25.  
  26. void loop_prescriptions (cb_prescription callback, bool add = true)
  27. {
  28.   //loop through all the elements
  29.     for (int i = 1; i <= prescriptions->noOfElements(); i++) {
  30.       //get the element and send it to callback for usage
  31.         Prescription * prescription = (Prescription *) prescriptions->removeNo(i); //removeNo, returns a pointer to the prescription class (Prescription *)
  32.         if (add) { //since the element has been removed, it should be readded unless the developer says so
  33.             prescriptions->add(prescription);
  34.         }
  35.         callback(prescription); //return the element
  36.     }
  37. }
  38.  
  39. /*
  40. error: cannot convert ‘list_prescriptions_by_doctor()::<lambda(Prescription*)>’ to ‘cb_prescription {aka void (*)(Prescription*)}’ for argument ‘1’ to ‘void loop_prescriptions(cb_prescription, bool)’
  41.      });
  42. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement