Salut à tous, j'essaye de développer une matrice de type générique, mais je me heurte à un probleme lors de la compilation. Voici mon code :
main.c :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 #include <stdio.h>
 #include <stdlib.h>
 #include "grid.h"
 #include "boat.h"
 
 int main (int argc, char * argv[]){
    TGrid grid;
 
    grid = cGrid (10,10);
 
    dGrid (grid,dBoat);
 
	return 0;
 }
boat.c :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
#include "boat.h"
 
 
 void dBoat (TBoat * pB)
 {
     pB->bDamage = 0;
     pB->bLength = 0;
     pB->bID = -1;
 }
boat.h :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef BOAT_H
#define BOAT_H
 
typedef
struct {
    int bID;// -1 pour un bateau non initialise
    unsigned int bLength;
    unsigned int bDamage;
}TBoat;
 
/*
 * N : dBoat
 * D : fonction de destruction d'un bateau
 * E : pB
 * S : /
 * R : /
 * P : /
 */
 void dBoat (TBoat * pB);
 
 
 
#endif
grid.h :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef GRID_H
#define GRID_H
 
 
struct TCell {
        void * element;
};
 
typedef struct {
        struct TCell ** matrix;
        unsigned int nbColumns;
        unsigned int nbLines;
} TGrid;
 
//En-Têtes des fonctions////////////////////////////////
/*
 * N : cGrid
 * D : Createur - Initialise une grille
 * E : pNbColumn (Le nombre de colonne), pnbLine (Le nombre de ligne)
 * S : /
 * R : TGrid
 * P : Les 2 entiers doivent être strictement positifs
 */
TGrid cGrid (unsigned int pNbColumn,unsigned int pnbLine);
 
/*
 * N : dGrid
 * D : Destructeur - Supprime une grille
 * E : pGrid (la grille), dElement (Un pointeur de fonction sur la fonction permettant de detruire l'element, cette fonction doit prendre en parametre un pointeur)
 * S : pGrid
 * R : /
 * P : /
 */
void dGrid (TGrid & pGrid,void (*dElement)(void *));
#endif
grid.c :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdlib.h>
#include <stdio.h>
#include "grid.h"
 
 
 
TGrid cGrid (unsigned int pNbColumn,unsigned int pnbLine)
{
    unsigned int i,j;
    TGrid grid;
    grid.matrix = NULL;
 
    //Allocation des espaces memoire correspondant aux lignes
    grid.matrix = (TCell **)malloc(pnbLine * sizeof(TCell *));
    if(grid.matrix == NULL){
        perror("cGrid : allocation error ");
        exit (1);
    }
 
    //Allocation des colonnes
    for (i=0;i<pnbLine;i++){
        grid.matrix[i] = NULL;
        grid.matrix[i] = (TCell *)malloc(pNbColumn * sizeof(TCell));
        if(grid.matrix[i] == NULL){
            perror("cGrid : allocation error ");
            exit (1);
        }
    }
 
    //Initialisation des cases à NULL
    for (i=0;i<pnbLine;i++)
        for (j=0;j<pNbColumn;j++)
            grid.matrix[i][j].element = NULL;
 
    //Initialisation des valeurs de la structure
    grid.nbColumns = pNbColumn;
    grid.nbLines = pnbLine;
 
    return grid;
}
 
 
void dGrid (TGrid & pGrid,void (*dElement)(void *)){
    unsigned int i,j;
 
    for (i=0;i<pGrid.nbLines;i++){
        for(j=0;j<pGrid.nbColumns;j++){
            //Suppression de l'element
            dElement(&(pGrid.matrix[i][j].element));
        }
        //Supression de la colonne
        free(pGrid.matrix[i]);
    }
    //Suppression des lignes
    free(pGrid.matrix);
 
    //Mise à jour de la structure
    pGrid.nbColumns = 0;
    pGrid.nbLines = 0;
}

Et enfin l'erreur de compilation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
main.cpp||In function 'int main(int, char**)':|
main.c|17|error: invalid conversion from 'void (*)(TBoat*)' to 'void (*)(void*)'|
main.c|17|error:   initializing argument 2 of 'void dGrid(TGrid&, void (*)(void*))'|
||=== Build finished: 2 errors, 0 warnings ===|

Il doit y avoir un problème lors de l'appel de dGrid, et surtout avec le pointeur de fonction, mais je ne vois pas vraiment d'où çà vient. Pouvez-vous m'aider, ou me rediriger vers une aide car j'ai pas mal cherché sans trouver la solution.