fork download
  1. #include <iostream>
  2. using std::cin;
  3. using std::cout;
  4.  
  5.  
  6. struct node {
  7. int data;
  8. node* prev;
  9. node* next;
  10. };
  11.  
  12. node* find(int,node*&);
  13. void afterElement(int,int,node*&,node*&,node* (*find)(int, node*&));
  14.  
  15. int main() {
  16. node* head = NULL;
  17. node* tail = NULL;
  18. // The program itself has a menu that allows for input of value in list but
  19. // for the sake of relevancy and shortness of code I dropped it out from here
  20.  
  21. int x, y;
  22. cout << "Insert 2 values: value you wish to insert, and value you wish to insert it after. ";
  23. cin >> x;
  24. cin >> y;
  25. afterElement(x,y,head,tail,find(y, head)); // here is the error "overloaded function..."
  26. return 0;
  27. }
  28.  
  29. node* find(int x,node*& head) {
  30. node* curr = head;
  31. while ((curr != NULL) && (curr->data != x))
  32. curr = curr->next;
  33. return curr;
  34. }
  35.  
  36. void afterElement(int x,int after,node*& head,node*& tail,node* (*find)(int x, node*& head)) {
  37. node* N;
  38. node* compared = (*find)(after,head);
  39. N->data = x;
  40. if (compared == NULL)
  41. cout << "There is no element " << after << " in the list!\n";
  42. else {
  43. if (compared->next == NULL) {
  44. compared->next = N;
  45. N->prev = compared;
  46. N->next = NULL;
  47. tail = N;
  48. } else {
  49. compared->next->prev = N;
  50. N->next = compared->next;
  51. compared->next = N;
  52. N->prev = compared;
  53. }
  54. }
  55. }
  56.  
  57.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:25:45: error: cannot convert ‘node*’ to ‘node* (*)(int, node*&)’ for argument ‘5’ to ‘void afterElement(int, int, node*&, node*&, node* (*)(int, node*&))’
     afterElement(x,y,head,tail,find(y, head)); // here is the error "overloaded function..."
                                             ^
stdout
Standard output is empty