簡體   English   中英

這些在PCL中的提升共享指針初始化是否不同?

[英]Are these boost shared pointer initializations in PCL different?

我一直在使用PCL一段時間,並看到幾種方法來初始化boost::shared_ptr 以下是我正在考慮的例子:

  • pointCloudType::Ptr cloud (new pointCloudType);
  • pointCloudType::Ptr cloud = pointCloudType::Ptr(new pointCloudType);
  • pointCloudType::Ptr cloud = pointCloudType::Ptr(new pointCloudType());

它們之間是否存在差異和/或使用其中一個優勢?

感謝@taketwo我得到了這個答案:

實施例2和3是相同的。 示例1應該是首選的,因為它是短路的並且不涉及對復制構造函數的調用。

因為示例1應該是首選,當指針已經聲明但未初始化時,要走的路是

cloud.reset(new pointCloudType);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM