为什么c++编译器找不到unique_ptr
Why g++ compiler is not able to find unique_ptr?
我正在尝试编译一个涉及unique_ptr的小c++代码,如下所示。
#include <iostream>
#include <memory>
using namespace std;
int main()
{
unique_ptr<int> p1(new int);
}
当我尝试使用g++编译代码时,它抛出'unique_ptr'未在此范围内声明。我试着在Linux上编译。甚至我尝试使用'-std=c++11'选项。它说'无法识别的命令行选项-std=c++11'。有谁能告诉我怎么解决这个问题吗?
你需要包含它,它来自<memory>
库
#include <memory>
根据GCC 4.4发布说明,在4.4之前,unique_ptr并不在GCC的标准c++库中。
所以你可能想先检查你的GCC版本,使用g++ --version
像@40two说。
相关文章:
- 为什么 std::unique 不调用 std::sort?
- CLANG 编译器 说:变量"PTR"可能未初始化
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 将 ptr 传递给 ptr 到 A 作为参数传递给 A 的函数是不好的做法吗?
- 为共享 ptr 向量实现复制 c'tor?
- 字符和整数中 **(ptr+1) 的值差异
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- 生成"unique"矩阵
- 如何将派生类从基 ptr 分配给 nlohmann::json
- 引用 std::shared:ptr 以避免引用计数
- 我对 std::unique(算法)C++有问题
- 为什么我不能在不进行任何转换的情况下将浮点数放入任何类型的 ptr 中?
- 在调用函数时,ptr** 和 ptr*& 之间是否有区别,或者首选C++?
- 另一种类型的智能ptr,比如具有弱refs的unique_ptr
- 尝试打印出 *ptr++ 的值,以了解它是如何工作的
- 如何控制共享 ptr 引用计数?
- std::shared_ptr::unique(),复制和线程安全
- 如何在C++03中用自定义谓词调用std::unique
- C++中的指针否定 (!ptr == NULL)
- C++14 unique_ptr并使用已删除的函数'std::unique-ptr' unique_ptr错误