gpt4 book ai didi

c++ - G++的奇怪错误

转载 作者:行者123 更新时间:2023-11-30 02:56:18 26 4
gpt4 key购买 nike

我通过 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;//对于 CV_SVM_C_SVC、CV_SVM_EPS_SVR 和 CV_SVM_NU_SVR

你能帮帮我吗

最佳答案

您可能对 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
^

关于c++ - G++的奇怪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15729271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com