My struct are like this :
typedef struct Bounds Bounds;
struct Bounds
{
int type;
double lb;
double ub;
};
typedef struct HelperGlpk HelperGlpk;
struct HelperGlpk
{
double *matrix_coefs;
double *obj_coefs;
Bounds *row_bounds;
Bounds *col_bounds;
int *column_of_coef;
int *row_of_coef;
int cpt_coef;
int cpt_contrainte;
};
I initiliaze them that way (on my main) :
HelperGlpk helper_glpk;
helper_glpk.matrix_coefs = malloc((nbr_coefs + 1) * sizeof(double));
helper_glpk.matrix_coefs[0] = 0;
helper_glpk.obj_coefs = malloc((nbr_colums + 1) * sizeof(double));
helper_glpk.obj_coefs[0] = 0;
helper_glpk.column_of_coef = malloc((nbr_colums + 1) * sizeof(int));
helper_glpk.column_of_coef[0] = 0;
helper_glpk.row_of_coef = malloc((nbr_rows + 1) * sizeof(int));
helper_glpk.row_of_coef[0] = 0;
helper_glpk.col_bounds = malloc((nbr_colums + 1) * sizeof(Bounds));
helper_glpk.row_bounds = malloc((nbr_rows + 1) * sizeof(Bounds));
helper_glpk.cpt_coef = 1;
helper_glpk.cpt_contrainte = 1;
Then, inside the function genere_contrainte_1() that I call this way : genere_contrainte_1(i, j, &helper_glpk, baie);
I want to access to the pointer helper_glpk->col_bounds[helper_glpk->cpt_coef]->type
but I got this error :
error: invalid type argument of ‘->’ (have ‘Bounds {aka struct Bounds}’)
helper_glpk->col_bounds[helper_glpk->cpt_coef]->type = GLP_DB;
Could you tell me what am I doing wrong ?
Edit : I DO want to access the pointer to ->type, because .type doesn't "save" the value for use outside the function genere_contrainte_1()
The col_bounds
member of the HelperGlpk
structure is being used as an array. Which is to say that
helper_glpk->col_bounds[helper_glpk->cpt_coef]
is an instance of the Bounds
structure, not a pointer to a Bounds
structure.
Hence, the correct syntax uses the dot notation
helper_glpk->col_bounds[helper_glpk->cpt_coef].type = GLP_DB;
helper_glpk->col_bounds
evaluates to a Bounds*
.
helper_glpk->col_bounds[helper_glpk->cpt_coef]
evaluates to a Bounds
.
Hence, you need to use:
helper_glpk->col_bounds[helper_glpk->cpt_coef].type = GLP_DB;
// ^^ Use . not ->
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.