main.cpp
#include <iostream>
#include "prototipo.hpp"
using namespace std;
int main(){
int num_elem;
int minimo;
void (*compare)(int* x, int* y);
compare comp;
comp = swap;
cout << "Inserire numero di elementi: ";
cin >> num_elem;
int *pointA = new int[num_elem];
ordinamentoArray (pointA, num_elem, comp);
}
prototipo.hpp
#ifndef PROTOTIPO_HPP
#define PROTOTIPO_HPP
void ordinamentoArray (int pointA[], int num_elem, compare comp);
void swap(int* x,int* y);
#endif
corpo.cpp
#include <iostream>
#include "prototipo.hpp"
using namespace std;
void swap(int* x, int* y){
int temp = *x;
*x = *y;
*y = temp;
}
void ordinamentoArray (int pointA[], int num_elem, compare comp){
int indice;
int indice2;
int temp;
for(indice=0; indice<num_elem; indice++){
for(indice2=indice; indice2>0 && pointA[indice2]<pointA[indice2-1]; indice2--){
if(pointA[indice2] < pointA[indice2-1]){
comp(&pointA[indice2], &pointA[indice2-1]);
}
}
}
}
These are the errors that appear. Among them, the main one is "error: 'compare' has not been declared". I honestly don't know what the mistake is. Can anyone give me a useful tip for solving the problem? I don't know maybe I made a mistake in declaring the function pointer, or I made a mistake passing the parameter