简体   繁体   中英

Strange error by G++

I am getting the following error by 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

My code is this :

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;

the code at line 146 is param.C = 7.0; // for CV_SVM_C_SVC, CV_SVM_EPS_SVR and CV_SVM_NU_SVR param.C = 7.0; // for CV_SVM_C_SVC, CV_SVM_EPS_SVR and CV_SVM_NU_SVR

Can you please help me.

You, probably, have a define for C . Look at the code:

#define C 42

class Foo
{

};

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

After preprocessing, the line fC = 7 will be changed to f.42 = 7 , so, it will trow an error.

PS: The clangs output looks more pretty

/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
          ^

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM