Skip to main content
gamedev.net
🔒 Locked

Function pointers

Started by Daos 2 replies 800+ views
Original Post
Daos
Daos
Why this initialization doesn't work? where the arguments are pointers to functions... int(*checkf[6])(unsigned __int64& mutare)={checkPawn,checkRock,checkKnight,checkBishop,checkKing,checkQueen}; ERROR<>'initializing' : cannot convert from '' to 'int (__cdecl *)(unsigned __int64 &)'

I guess it's something about calling convention......

Ruben3d
Ruben3d
try this:

int(*(checkf[6]))(unsigned __int64& mutare)={checkPawn,checkRock,checkKnight,checkBishop,checkKing,checkQueen};

or this:

int(*checkf[])(unsigned __int64& mutare)={checkPawn,checkRock,checkKnight,checkBishop,checkKing,checkQueen};

or maybe a mix of the two previous:

int(*(checkf[]))(unsigned __int64& mutare)={checkPawn,checkRock,checkKnight,checkBishop,checkKing,checkQueen};

This last attempt appears to be correct, according to the operator precedence table shown here.
Daos
Daos
Sorry my mistake the definitions of the function were OK
but the prototypes were not So I freked out that's a calling convention problem.Sorry for wasting your time.Thanks anyway![smile]
doynax
doynax
Quote:
Original post by Daos
Sorry my mistake the definitions of the function were OK
but the prototypes were not So I freked out that's a calling convention problem.Sorry for wasting your time.Thanks anyway![smile]

Here's a tip: Typedef complex types! It'll save you a lot of headaces when dealing with function pointers and stl containers.

typedef int (*check_piece)(unsigned __int64 &mutare);check_piece checkf[] = {  checkPawn, checkRock, checkKnight, checkBishop, checkKing, checkQueen };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.