<分区>
如何在下面的代码中传递 unique_ptr
?此代码无法编译。
int abc(int*& a)
{
return 1;
}
int main()
{
std::cout<<"Hello World";
std::unique_ptr<int> a(new int);
abc(a.get());
return 0;
}
标签 c++ unique-ptr
<分区>
如何在下面的代码中传递 unique_ptr
?此代码无法编译。
int abc(int*& a)
{
return 1;
}
int main()
{
std::cout<<"Hello World";
std::unique_ptr<int> a(new int);
abc(a.get());
return 0;
}
最佳答案
您可以通过 const 引用或引用来传递它,例如:
int abc(const std::unique_ptr<int>& a)
关于c++ - unique_ptr 在 C++ 中的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55843800/