我正在尝试编译C ++代码,下面是代码段,我在此代码段下面添加了错误。
// Move constructor
CLM(const CLM&& other)
{
this->detection_success = other.detection_success;
this->tracking_initialised = other.tracking_initialised;
this->detection_certainty = other.detection_certainty;
this->model_likelihood = other.model_likelihood;
this->failures_in_a_row = other.failures_in_a_row;
pdm = other.pdm;
params_local = other.params_local;
params_global = other.params_global;
detected_landmarks = other.detected_landmarks;
landmark_likelihoods = other.landmark_likelihoods;
patch_experts = other.patch_experts;
landmark_validator = other.landmark_validator;
triangulations = other.triangulations;
kde_resp_precalc = other.kde_resp_precalc;
}
// Assignment operator for rvalues
CLM & operator= (const CLM&& other)
{
this->detection_success = other.detection_success;
this->tracking_initialised = other.tracking_initialised;
this->detection_certainty = other.detection_certainty;
this->model_likelihood = other.model_likelihood;
this->failures_in_a_row = other.failures_in_a_row;
pdm = other.pdm;
params_local = other.params_local;
params_global = other.params_global;
detected_landmarks = other.detected_landmarks;
landmark_likelihoods = other.landmark_likelihoods;
patch_experts = other.patch_experts;
landmark_validator = other.landmark_validator;
triangulations = other.triangulations;
kde_resp_precalc = other.kde_resp_precalc;
return *this;
}
我收到以下错误:
In file included from ../../Demo/Pack/CLM/include/CLM_utils.h:9:0,
from ../../Demo/Pack/CLM/src/CCNF_patch_expert.cpp:3:
../../Demo/Pack/CLM/include/CLM.h:170:16: error: expected ‘,’ or ‘...’ before ‘&&’ token
CLM(const CLM&& other)
^
../../Demo/Pack/CLM/include/CLM.h:170:24: error: invalid constructor; you probably meant ‘CLMTracker::CLM (const CLMTracker::CLM&)’
CLM(const CLM&& other)
^
../../Demo/Pack/CLM/include/CLM.h:192:28: error: expected ‘,’ or ‘...’ before ‘&&’ token
CLM & operator= (const CLM&& other)
^
../../Demo/Pack/CLM/include/CLM.h: In member function ‘CLMTracker::CLM& CLMTracker::CLM::operator=(CLMTracker::CLM)’:
../../Demo/Pack/CLM/include/CLM.h:194:29: error: ‘other’ was not declared in this scope
this->detection_success = other.detection_success;
我不知道代码有什么问题以及错误意味着什么?请有人帮忙。
答案 0 :(得分:3)
const CLM&& other
是 r值参考。这些是C ++ 11标准中对C ++的新增功能。将-std=c++11
(或-std=c++0x
(如果您使用的是较旧的编译器,请查看文档)添加到编译器调用中。
答案 1 :(得分:1)
您使用的&&
是rvalue reference,它只在c++11
中有意义。因此,您应该告诉编译器您正在使用c++11
。在GCC中,您可以通过传递-std=c++11