Netwars

Zjedź na dół

C : Wskaznik do funkcji jako pole struktury

[#1]
11.02.2010 18:02

Mam tutaj nie lada problem, bo chce zaaplikowac pewna obiektowosc w grze ktora pisze i nie moge wyczaic wskaznikow na funkcje, tak by byly polem w strukturze :p Wywala mi ze ostatnia linijka nie jest funkcja. Ktoś coś poradzi?

typedef struct _METHODS_{
void (*animate_player);
} METHODS;

typedef struct _PLAYER_{
//zmienne
METHODS *Methods;
} PLAYER;

void animate_player(PLAYER *Player, int x, int y)
{
//kod
}
PLAYER *Player = (PLAYER*)malloc(sizeof(PLAYER));

Player->Methods->animate_player=animate_player;
Player->Methods->animate_player(Player,x,y);

aha :d bez jechania po mnie bo pierwszy raz tego probuje ;d

[#2]
11.02.2010 18:17

void (*animate_player);
zamień na
void (*animate_player)(____);

i wpisz tam typy parametrów w miejscu ____

[#3]
11.02.2010 18:25

void (*animate_player)(PLAYER *Player,int x,int y);

error: expected ')' before '*' token
warning: no semicolon at end of struct or union

[#4]
11.02.2010 18:31

raczej tak:

void (*animate_player)(PLAYER*,int,int);

tyle, że PLAYER jest niżej, więc musisz wyżej jakąś wczesną deklaracje zrobić

[#5]
11.02.2010 18:33

struct _PLAYER_;
typedef struct _PLAYER_ PLAYER;

typedef struct _METHODS_{
void (*animate_player)(PLAYER*,int,int);
} METHODS;

struct _PLAYER_{
//zmienne
METHODS *Methods;
}

troche w ciemno, bo nie mam teraz w czym sprawdzić

[#6]
11.02.2010 18:38

smiga :D

dzieki wielkie.

Zaloguj się, żeby odpowiedzieć.