error: 'make_unique' is not a member of 'std'
时间: 2023-12-25 07:03:00 浏览: 62
如果编译器报错 "'make_unique' is not a member of 'std'",那可能是因为你的编译器版本过旧,不支持 C++14 的 `std::make_unique` 函数。你可以尝试使用 C++11 的 `std::unique_ptr` 和 `new` 运算符来代替 `std::make_unique`。或者,你也可以升级你的编译器到支持 C++14 的版本。
相关问题
error: ‘make_unique’ is not a member of ‘g2o’
This error indicates that the 'make_unique' function is not recognized as a member of the 'g2o' namespace. The 'make_unique' function is a C++14 feature that is used to create a unique_ptr object with a dynamically allocated object.
To resolve this error, you can try a few potential solutions:
1. Update your compiler: Make sure you are using a C++14-compliant compiler that supports the 'make_unique' function. If you're using an older compiler version, it may not recognize this function. Upgrading to a newer version or enabling C++14 support in your current compiler might solve the issue.
2. Check g2o version: Verify that you are using a version of g2o that supports C++14. Older versions of g2o might not have implemented the 'make_unique' function. If necessary, update to a newer version of g2o that supports C++14.
3. Use alternative implementations: If upgrading your compiler or g2o version is not feasible, you can consider using alternative implementations for creating unique_ptr objects. Instead of 'make_unique', you can use 'std::unique_ptr' directly with 'new' to allocate and initialize the object.
Here's an example of using 'std::unique_ptr' instead of 'make_unique':
```cpp
std::unique_ptr<YourObjectType> ptr(new YourObjectType());
```
Remember to replace 'YourObjectType' with the actual type you want to allocate.
By applying one of these solutions, you should be able to resolve the error and use the 'make_unique' function in your code successfully.
In function ‘void bundleAdjustmentG2O(const VecVector3d&, const VecVector2d&, const cv::Mat&, Sophus::SE3d&)’: /home/jerry/slambook2/ch7/pose_estimation_3d2d.cpp:319:10: error: ‘make_unique’ is not a member of ‘g2o’ 319 | g2o::make_unique<BlockSolverType>(g2o::make_unique<LinearSolverType>()));
在您的代码中,出现了一个错误,指示 g2o 中没有名为 'make_unique' 的成员。这是因为在较新的 g2o 版本中,'make_unique' 函数已经被移除。相反,您可以使用标准库中的 'std::make_unique' 函数来创建独立指针。
要解决此问题,请将 'g2o::make_unique' 更改为 'std::make_unique',并确保您的代码正确包含了 `<memory>` 头文件。
修改后的代码应如下所示:
```cpp
std::unique_ptr<BlockSolverType> solver_ptr = std::make_unique<BlockSolverType>(
std::make_unique<LinearSolverType>());
```
这样应该能够解决您遇到的问题。如果还有其他问题,请随时提问。