So I was trying to accomplish to write a struct with pointer functions in it and this is what I wrote
typedef struct Coordinates {
float x;
float y;
} Coord;
typedef struct Parallelograms {
Coord upperR, lowerL;
float base;
float (*areaFunc)(float base, Coord upperR, Coord lowerL);
float (*perimeter)(float base, Coord upperR, Coord lowerL);
} Parallelogram;
This is where I define the function:
float area(float base, Coord upperR, Coord lowerL) {
return (base*(upperR.y-lowerL.y));
}
And then in some other function I call it this way:
Parallelogram para;
para.areaFunc = area;
The only thing is that when I try to print it
printf("Area = %.2f", array[i].area);
(with array being the array of Parallelogram type of objects) It returns this error when compiling:
format specifies type 'double' but the argument has type 'float ()(float, Coord, Coord)' (aka 'float ()(float, struct Coordinates, struct Coordinates)') [-Werror,-Wformat] ...printf("# Area = %.2f #\n", array[I].areaFunc);
I thought I got the pointer functions right, so how can I convert the pointer function to the actual value that it should return?