‘make_unique’ is not a member of ‘std’
时间: 2024-05-16 14:12:42 浏览: 11
这个错误通常是由于使用了旧版本的编译器或者编译器不支持C++11标准导致的。`make_unique` 是 C++11 中引入的一种新的内存管理方式,用于创建唯一所有权的动态分配对象的智能指针。如果你的编译器版本太低或者不支持 C++11 标准,就会出现这个错误。
解决这个问题的方法是升级编译器,或者在代码中手动实现 `make_unique` 的功能。以下是一个简单的实现:
```c++
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
```
将这个代码加入到你的源码中,就可以使用 `make_unique` 了。
相关问题
error: 'make_unique' is not a member of 'std'
如果编译器报错 "'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.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)