gpt4 book ai didi

c++ - 如何在 clang 3.4 中使用 make_unique?

转载 作者:太空狗 更新时间:2023-10-29 21:18:46 28 4
gpt4 key购买 nike

使用 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com