Napisałem taki kod:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
struct point
{
int x;
int y;
struct point * wsk;
//void (*present)(struct point *);
void (*present)(void);
};
/*
void presentation(struct point * temp)
{
printf("Adres struktury: %d, x=%d, y=%d\n", (int)(temp->wsk), temp->x, temp->y);
}
*/
void presentation()
{
printf("Adres struktury: %d, x=%d, y=%d\n", (int)(temp->wsk), temp->x, temp->y);
}
struct point new_point(int a, int b)
{
struct point * temp = malloc(sizeof(struct point));
temp -> x = a;
temp -> y = b;
temp -> wsk = temp;
temp -> present = presentation;
return (*temp);
}
int main()
{
struct point a = new_point(3, 5);
struct point b = new_point(9, -1);
a.present();
b.present();
getchar();
return 0;
}
i mam jedno zasadnicze pytanie co do funkcji o nazwie presentation
na którą pokazuje wskaźnik zdefiniowany w strukturze point
.
Otóż zależy mi żeby po stworzeniu obiektu swoistym konstruktorem new_point
pod wskaźnik zapisywał się adres funkcji do wywołania i jak widać tak też się robi, jednakże zależałoby mi także i na tym aby później z poziomu wywołania tej funkcji wypisać współrzędne tej struktury.
Po odkomentowaniu to działa ale mi bardzo zależy także na tym żeby wywołanie było takie:
a.present()
a nie takie: a.present(&a)
Da się to jakoś tak napisać żeby tak wyglądało właśnie wywołanie funkcji i żeby ta funkcja wtedy wypisywała dokładnie parametry punktu a
a nie innego.