【发布时间】:2021-04-21 21:09:36
【问题描述】:
我最近尝试运行一个使用智能指针的代码。正如标题所说,我使用 Ninja(版本 1.10.2)、Meson(0.57.2)和 Qt Creator 4.14.2。 我有以下 meson.build :
project('RayTracerDemo',
'cpp',
version: '0.0.0',
default_options: [
'c_std=c2x',
'cpp_std=c++20',
'warning_level=3',
'optimization=3',
'werror=true'
]
)
includeDir = include_directories([])
sources = files([
'main.cpp'
])
headers = files([])
raytracer_exe = executable(
'RayTracerDemo',
sources: sources + headers,
include_directories: includeDir,
dependencies: []
)
但我仍然收到以下错误:
/~/programs/RayTracerDemo/main.cpp:189: error: ‘make_unique’ is not a member of ‘std’
../main.cpp: In function ‘void render(const std::vector<Sphere>&)’:
../main.cpp:189:52: error: ‘make_unique’ is not a member of ‘std’
189 | threads[height * width + width] = std::make_unique<std::thread>([&]() -> void
| ^~~~~~~~~~~
../main.cpp:189:52: note: ‘std::make_unique’ is only available from C++14 onwards
对于以下几行:
threads[height * width + width] = std::make_unique<std::thread>([&]() -> void
{
float xx = (2 * ((x + 0.5) * invWidth) - 1) * angle * aspectratio;
float yy = (1 - 2 * ((y + 0.5) * invHeight)) * angle;
Vec3f raydir(xx, yy, -1);
raydir.normalize();
*pixel = trace(Vec3f(0), raydir, spheres, 0);
});
线程是这样声明的向量:
std::vector<std::unique_ptr<std::thread>> threads(height * width);
Qt Creator 文档说使用 Meson here 不支持某些功能,但这不包括编译器版本问题。
【问题讨论】:
-
你的编译版本是什么?如果你使用 cpp_std=c++14 怎么办?
-
我有 g++ (GCC) 10.2.0,并且我已经尝试过 c++14 以上所有可能的版本,包括它。
标签: c++ qt smart-pointers ninja meson-build