- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
使用 Travis-CI
我正在尝试构建一个使用 std::make_unique
的 C++ 项目。但是我得到一个构建错误:
no member named 'make_unique' in namespace 'std'
mFiles.emplace_back(std::make_unique<File>(*this, rec));
我包含了memory
,这段代码在 VS2013 和 gcc 4.8 中使用 -std=c++14
编译。如果我在 clang 3.4 中使用这个标志,我会得到一个错误:
error: invalid value 'c++14' in '-std=c++14'
根据 clang 文档:
http://clang.llvm.org/cxx_status.html
我应该使用 -std=c++1y
但这仍然会产生相同的在命名空间“std”中没有名为“make_unique”的成员
。那么我该如何让它发挥作用呢?
最佳答案
这不依赖于编译器,而是依赖于标准库的实现。 std::make_unique
不是核心语言特性,而是库函数。
检查Travis使用的libstdc++
版本。
根据 the GCC 4.9 changelog , std::make_unique
在 GCC 4.9 发布时被引入 libstdc++
。
如果 Travis 使用的是 4.9 之前的 GCC 版本,很可能它的 libstdc++
版本还没有 std::make_unique
。
关于c++ - 如何在 clang 3.4 中使用 make_unique?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29432033/
struct Foo{}; std::make_unique 之间有什么区别?和 std::make_unique> ? 最佳答案 std::make_unique创建一个 Foo具有动态存储持续时间
我正在实现循环数组数据结构,其代码如下所示: struct CircularArrayException : public std::exception { std::string msg;
全部, 我正在使用 C++14 并正在制作一个或多或少的标准单例。我正在使用最新的 Visual Studio 2017。此代码有效: #include class A { public: st
我想知道使用智能指针(如下面代码中的 Box3 )声明 Box 是否比(对我来说更经典)声明有任何优势调用构造函数(如下面代码中的 Box2)或者这两种构造之间的差异本质上是主观偏好的问题。 #inc
我在构建时不断收到以下错误, use of undeclared identifier 'make_unique' m_planet = make_unique(); 我的头文件给出了错误, #inc
我需要一个类作为延迟工厂工作,保存参数以创建另一个类并稍后及时调用 make_unique。到目前为止,我没有任何运气让可变模板版本工作。任何帮助将不胜感激(下面的最小非工作版本)。 template
https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique写道 std::make_unique 可以实现为 template st
我正在尝试为 std::unique_ptr 创建和使用 make_unique,就像 std::make_shared 存在于 std::shared_ptr described here .赫伯萨
作为 this 的后续行动发布后我想知道它的 make_unique 实现如何与分配函数临时缓冲区数组一起使用,例如以下代码。 f() { auto buf = new int[n]; // te
澄清一下,使用 make_unique 仅在表达式中有多个分配时才增加异常安全性,而不仅仅是一个,对吗?例如 void f(T*); f(new T); 是完全异常安全的(就分配和东西而言),而 vo
为什么没有std::make_unique标准 C++11 库中的函数模板?我发现 std::unique_ptr p(new SomeUserDefinedType(1, 2, 3)); 有点冗长。
考虑以下基类和派生类。 class base { public: int i{9}; virtual void func() { cout ptr{new d
在下面的代码中,有什么方法可以将参数传递给 demo使用时的构造函数 std::make_unique()分配一个 demo[]大批? class demo{ public: int info
有没有办法使用 make_unique 并将函数的输出作为参数传递? auto loadedSurface1 = std::unique_ptr(IMG_Load(path.c_str())); au
这个问题在这里已经有了答案: Template deduction for function based on its return type? (6 个答案) 关闭 4 年前。 例如我得到了这段代
make_unique 如果设计成这样,会不会更有用: template unique_ptr make_unique( ArgT ...args ) { return unique_ptr(
我遇到了 make_unique 的问题,我对此一头雾水。 _replace_find = unique_ptr(new Fl_Input{ 80, 10, 210, 25, "Find:" });
我无法找到任何关于如果将空指针传递给 std::make_unique 会发生什么的文档。 是否抛出异常? 最佳答案 std::make_unique将传递给匹配目标构造函数的所有参数转发。因此,如果
这个问题在这里已经有了答案: using c++ aggregate initialization in std::make_shared (3 个答案) 关闭 5 年前。 刚开始学习智能指针 st
我有一个 Factory 的小例子设计模式,我对这部分很感兴趣: std::make_unique(*this) ...尤其是*this . 这是否意味着 clone()方法返回 std::uniqu
我是一名优秀的程序员,十分优秀!