2016-10-17 64 views
0

我想做一個元組的元組,pcl :: visualization :: PointCloudColorHandler>但是當我將相應類型的參數傳遞到std :: make_tuple,它說,作爲pcl :: PointCloud傳遞的參數實際上是pcl :: PointCloud & &,如果我正確的話是一個右值引用。我不明白類型pcl :: PointCloud如何成爲右值引用。下面是代碼:make_tuple傳遞類型T作爲T &&,當期待T作爲模板化參數

pcl::PointCloud<pcl::PointXYZRGB> cloud; 
pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr constCloud(&cloud); 
pcl::io::loadPCDFile<pcl::PointXYZRGB>(file.getPCDFilePath().string(), cloud); 
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgbHandler(constCloud); 
associatedClouds.insert(std::make_tuple<std::string, pcl::PointCloud<pcl::PointXYZRGB>, pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> >(file.getPCDFileName(), cloud, rgbHandler)); 
visualizedFiles.push_back(cloud); 

我得到的錯誤是:

/Users/wfehrnstrom/CmakeTest/map.cpp:53:29: error: no matching function for call to 'make_tuple' 
    associatedClouds.insert(std::make_tuple<std::string, pcl::PointCloud<pcl::PointXYZRGB>, pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> >(file.getPCDFileName(), cloud, rgbHandler)); 
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/tuple:868:1: note: candidate function [with _Tp = <std::__1::basic_string<char>, pcl::PointCloud<pcl::PointXYZRGB>, pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB>>] not viable: no known conversion from 'pcl::PointCloud<pcl::PointXYZRGB>' to 'pcl::PointCloud<pcl::PointXYZRGB> &&' for 2nd argument 
make_tuple(_Tp&&... __t) 

我幾乎失去了。謝謝。

+0

從'make_tuple'中刪除'''',只是'std :: make_tuple(file.getPCDFileName(),cloud,rgbHandler);'讓模板參數扣除完成它的工作。 – 101010

+1

請格式化您的問題。它看起來像一隻狗吃了一半。嵌入式代碼片段介於反引號之間,例如:'\'foo \''。 –

回答

2

從不使用帶顯式模板參數的make_tuple

這就是我記得微軟STL維護者的一句話,原因是make_tuple足夠聰明,可以去掉額外的引用,並且明確地聲明模板參數可以擊敗它的目的。

另一件事是file.getPCDFileName()Rvalue Reference, 函數返回的臨時值是右值。您可以使用本地變量auto filename = file.getPCDFileName(),然後使用make_tuple(file_name, ...

相關問題