这个函数 "a::b::ptr function(value)" 在 C++ 中如何调用?

siv*_*iha 1 c++ pointers scope function

我实际上是 C++ 的新手,我试图弄清楚编译器如何执行以下行:

pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
Run Code Online (Sandbox Code Playgroud)

我知道pcl::ModelCoefficents()创建了一个类型的堆内存并将其指针传递给 function coefficients()。让我感到困惑的是,我们不应该使用如下所示的箭头运算符:

pcl::ModelCoefficients::Ptr->coefficients (new pcl::ModelCoefficients ());
Run Code Online (Sandbox Code Playgroud)

Som*_*ude 5

该声明

pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
Run Code Online (Sandbox Code Playgroud)

可以改写为

pcl::ModelCoefficients::Ptr coefficients = new pcl::ModelCoefficients;
Run Code Online (Sandbox Code Playgroud)

我认为第二个版本更好地展示了正在发生的事情。

简而言之,该行定义了一个以type命名的变量。然后它以 的结果初始化。coefficientspcl::ModelCoefficients::Ptrcoefficientsnew pcl::ModelCoefficients