我想将结构作为参数传递给函数。但是我编译时失败了。 这是我的结构定义。它在svm.h中定义,并在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
这是我的函数定义。它在syll_fragmentation.h中声明,并在syll_fragmentation.c中定义 声明:
void real_time_predict(struct svm_model *model, SAMPLE *sum_normal);
定义:
void real_time_predict(struct svm_model *model, SAMPLE *sum_normal) {}
在主函数中,我将此函数称为:
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);
我得到的错误是无效的初始化器,该初始化器使用real_time_predict函数进行引用。我正在使用gcc进行编译。这是错误日志:
syll_fragmentation.c:217:13: error: invalid initializer
第217行是real_time_predict函数的声明。我不知道为什么,请帮助我,谢谢大家!