2014-09-11 97 views
0

我想编译一个C++代码,下面是代码片段,我在该代码片段下面添加了错误。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; 

我不知道什么是错的代码,意味着什么错误?有人可以帮忙吗?

+1

似乎你的编译器不支持C++ 11。 – 2014-09-11 11:15:35

+1

1)您是否在启用C++ 11支持的情况下进行编译? 2)const的右值引用是毫无意义的。 – 2014-09-11 11:15:55

+0

无关:CLM的传统TLA让我微笑,我必须承认。 – WhozCraig 2014-09-11 11:16:40

回答

3

const CLM&& otherr值参考。这些是C++ 11标准新增加的C++。将-std=c++11(或-std=c++0x,如果您使用较旧的编译器,请检查文档)添加到您的编译器调用中。

+0

接受为答案,因为它是先回答。 @Ivaylo Strandjev感谢您的回答以及您的参考链接。 – sathishkumar 2014-09-11 11:42:10

1

您正在使用的是&&这是一个rvalue reference,它只在c++11有意义。因此,你应该告诉你的编译器你正在使用c++11。在GCC中,你通过传递-std=c++11