G ++的奇怪错误

时间:2013-03-31 12:16:25

标签: c++ compilation g++

我通过g ++收到以下错误:

wormAlgo.cpp: In function ‘void svm(cv::Mat&, cv::Mat&, cv::Mat&, cv::Mat&)’:
wormAlgo.cpp:146:8: error: expected unqualified-id before numeric constant
wormAlgo.cpp:146:8: error: expected ‘;’ before numeric constant

我的代码是:

void svm(cv::Mat& trainingData, cv::Mat& trainingClasses, cv::Mat& testData, cv::Mat& testClasses) 
{
    CvSVMParams param = CvSVMParams();

    param.svm_type = CvSVM::C_SVC;
    param.kernel_type = CvSVM::RBF; //CvSVM::RBF, CvSVM::LINEAR ...
    param.degree = 0; // for poly
    param.gamma = 20; // for poly/rbf/sigmoid
    param.coef0 = 0; // for poly/sigmoid
    param.C = 7.0; // for CV_SVM_C_SVC, CV_SVM_EPS_SVR and CV_SVM_NU_SVR
    param.nu = 0.0; // for CV_SVM_NU_SVC, CV_SVM_ONE_CLASS, and CV_SVM_NU_SVR
    param.p = 0.0; // for CV_SVM_EPS_SVR
    param.class_weights = NULL; // for CV_SVM_C_SVC
    param.term_crit.type = CV_TERMCRIT_ITER +CV_TERMCRIT_EPS;
    param.term_crit.max_iter = 1000;
    param.term_crit.epsilon = 1e-6;

第146行的代码为param.C = 7.0; // for CV_SVM_C_SVC, CV_SVM_EPS_SVR and CV_SVM_NU_SVR

你能帮我吗?

1 个答案:

答案 0 :(得分:3)

您可能有C的定义。看一下代码:

#define C 42

class Foo
{

};

void f()
{
    Foo f;
    f.C = 7;
}

预处理后,行f.C = 7将更改为f.42 = 7,因此会产生错误。

PS:clangs输出看起来更漂亮

/home/soon/Src/C++/main/main.cpp:14:7: error: expected unqualified-id
    f.C = 7;
      ^
/home/soon/Src/C++/main/main.cpp:4:11: note: expanded from macro 'C'
#define C 42
          ^