jaw*_*awa 5 c++ c++11 clang-tidy
Clang-Tidy: Do not implicitly decay an array into a pointer 我不明白为什么 Clang-Tidy在以下示例中产生错误:
struct Foo {
explicit Foo(std::string _identifier) : identifier(std::move(_identifier)) {}
std::string identifier;
};
struct Bar {
template<typename... Ts>
explicit Bar(Ts &&...args) : foo(std::forward<Ts>(args)...) {} // <-- Error
Foo foo;
};
Bar bar("hello world");
Run Code Online (Sandbox Code Playgroud)
从错误中我了解到,"hello world"作为类型(或类似)的数组const char[11]会在 期间衰减到const char*某个位置std::forward。但为什么以及如何修复这个错误呢?std::make_shared<Foo>("hello world")与 的用法非常相似std::forward并且确实有效。
| 归档时间: |
|
| 查看次数: |
1637 次 |
| 最近记录: |