首页 > 解决方案 > invalid initializer in a struct pointer function

问题描述

I want to pass a struct as parameter in a function. But it's failed when i compile it. Here is my struct definition. It's defined in svm.h and declaration in svm.cpp

#ifdef __cplusplus
extern "C" {
#endif
struct svm_model
{
    struct svm_parameter param; /* parameter */
    int nr_class;       /* number of classes, = 2 in regression/one class 
    svm */
    int l;          /* total #SV */
    struct svm_node **SV;       /* SVs (SV[l]) */
    double **sv_coef;   /* coefficients for SVs in decision functions 
    (sv_coef[k-1][l]) */
    double *rho;        /* constants in decision functions (rho[k*(k-1)/2]) 
    */
    double *probA;      /* pariwise probability information */
    double *probB;
    int *sv_indices;        /* sv_indices[0,...,nSV-1] are values in 
    [1,...,num_traning_data] to indicate SVs in the training set */

                            /* for classification only */

    int *label;     /* label of each class (label[k]) */
    int *nSV;       /* number of SVs for each class (nSV[k]) */
                    /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
                    /* XXX */
    int free_sv;        /* 1 if svm_model is created by svm_load_model*/
                        /* 0 if svm_model is created by svm_train */
};
....
#ifdef __cplusplus
}
#endif

And here is my function definition. It is declared in syll_fragmentation.h and defined in syll_fragmentation.c Declaration:

 void real_time_predict(struct svm_model *model, SAMPLE *sum_normal);

Definition:

 void real_time_predict(struct svm_model *model, SAMPLE *sum_normal) {}

In main function, i call this function :

 struct svm_model *model;
 if ((model = svm_load_model(model_path)) == 0) {
        fprintf(stderr, "cant load model file \n");
        exit(1);
 }

 SAMPLE *sum_normal = (SAMPLE*)malloc(sizeof(SAMPLE) * 91);
 mfcc_load_normalized_sum(sum_normal, sum_path);
 real_time_predict(model, sum_normal);

The error i got is invalid initializer, which reference with real_time_predict function. I'm using gcc to compile. And here is error log:

syll_fragmentation.c:217:13: error: invalid initializer

line 217 is declaration of real_time_predict function.I don't know why, please help me, thank you guys!!!

标签: c

解决方案


推荐阅读