2013-11-01 51 views
2

代碼轉換:C到C++轉換雜項聲明

struct CurrentFrameCloudView 
{ 
    CurrentFrameCloudView() : cloud_device_ (480, 640), cloud_viewer_ ("Frame Cloud Viewer") 
    { 
    cloud_ptr_ = PointCloud<PointXYZ>::Ptr (new PointCloud<PointXYZ>); 

    cloud_viewer_.setBackgroundColor (0, 0, 0.15); 
    cloud_viewer_.setPointCloudRenderingProperties (visualization::PCL_VISUALIZER_POINT_SIZE, 1); 
    cloud_viewer_.addCoordinateSystem (1.0); 
    cloud_viewer_.initCameraParameters(); 
    cloud_viewer_.setPosition (0, 500); 
    cloud_viewer_.setSize (640, 480); 
    cloud_viewer_.setCameraClipDistances (0.01, 10.01); 
    } 

    void 
    show (const KinfuTracker& kinfu) 
    { 
    kinfu.getLastFrameCloud (cloud_device_); 

    int c; 
    cloud_device_.download (cloud_ptr_->points, c); 
    cloud_ptr_->width = cloud_device_.cols(); 
    cloud_ptr_->height = cloud_device_.rows(); 
    cloud_ptr_->is_dense = false; 

    cloud_viewer_.removeAllPointClouds(); 
    cloud_viewer_.addPointCloud<PointXYZ>(cloud_ptr_); 
    cloud_viewer_.spinOnce(); 
    } 

    void 
    setViewerPose (const Eigen::Affine3f& viewer_pose) { 
    ::setViewerPose (cloud_viewer_, viewer_pose); 
    } 

    PointCloud<PointXYZ>::Ptr cloud_ptr_; 
    DeviceArray2D<PointXYZ> cloud_device_; 
    visualization::PCLVisualizer cloud_viewer_; 
}; 

問題:

能有人給我解釋一下這行代碼?

void 
setViewerPose (const Eigen::Affine3f& viewer_pose) { 
     ::setViewerPose (cloud_viewer_, viewer_pose); // especially here ... 
} 

歡迎任何幫助!

+2

雙冒號是對全局命名空間的引用。請參見[關於此運算符的此問題](http://stackoverflow.com/questions/4269034/what-is-the-meaning-of-prepended-double-colon-to-class-name) – ghik

+0

使用範圍運算符: :,以明確說明範圍。正如@ghik所說,沒有一個範圍說明,看起來全球化。 – ChuckCottrill

回答

4
::setViewerPose (cloud_viewer_, viewer_pose); 

該行稱爲全局函數setViewerPose()。雙冒號::確保它調用全局名稱空間中的函數,而不是當前類中的函數。

通常,::用於訪問命名空間成員la std::cout或靜態類成員,如MySingleton::instance。如果省略左邊的名稱空間/類名稱,則它訪問全局項目。

+0

我有一個雖然類似於此,但我與代碼的C部分混淆。您的答案有助於解決問題!謝謝!我儘快接受! – alap

+1

The ::不是可選的。由於C++在考慮重載和參數解析之前解析了名稱範圍,因此它不會考慮全局'setViewerPose'並且會抱怨'CurrentFrameCloudView :: setViewerPose'的參數不匹配。參見例如http://stackoverflow.com/a/72075/25507。 –

+0

@JoshKelley啊,謝謝。我從我的答案中刪除了這個。 –