Je suis en train de pointer une fonction de la structure à une autre fonction d'une autre structure,Fonction points de struct à une autre fonction d'autres struct
PLASE considèrent ceci:
// Main Structure:
typedef struct
{
int GetValA(int a)
{
return a * 2;
}
} x;
typedef struct
{
int(*HGetValA)(int); // Pointer function
} hookx;
// Then
int main()
{
x v1;
hookx* v2;
v2 = (hookx*)&v1; // or 0x0 memory address
// Now declaring pointer function
v2->HGetValA = (int(*)(int))&v1.GetValA; // Pointing to function of the main structure.
}
pour moi, cela semble bon, mais au moment de la compilation me donne l'erreur:
[Warning] converting from 'int (x::)(int)' to 'int ()(int)' [-Wpmf-conversions]
ce n'est pas possible sans un nom? – nikomaster
Cela fonctionne pour ajouter un mot-clé 'static' avant' GetValA() 'dans ce programme. mais peut-être que ce n'est pas ce que vous écrivez exactement. – uscq