Function 测试编译报错
gcc13.1 -std=c++20
部分报错信息如下: https://godbolt.org/z/KzGoGbdvK error: no matching function for call to 'forward(main()::<lambda(int)>&)' 29 | explicit _FuncImpl(std::in_place_t, _CArgs &&...__args) : _M_f(std::forward(__args)...) {}
GPT:std::make_unique 尝试调用 _FuncImpl 的构造函数时,传递的参数类型不匹配导致的。 确保 _FuncImpl 的构造函数能够正确处理函数指针的引用。通过添加一个额外的构造函数来处理。 能编译通过的代码:https://godbolt.org/z/h4KMKoMYc
std::forward(__args)
改成 std::forward<_CArgs>(__args)
即可
无法顺畅的大口呼吸,是活着的最好证明
---原始邮件--- 发件人: @.> 发送时间: 2024年9月22日(周日) 晚上7:31 收件人: @.>; 抄送: @.***>; 主题: [parallel101/stl1weekend] Function 测试编译报错 (Issue #6)
gcc13.1 -std=c++20
部分报错信息如下: https://godbolt.org/z/KzGoGbdvK error: no matching function for call to 'forward(main()::<lambda(int)>&)' 29 | explicit _FuncImpl(std::in_place_t, _CArgs &&...__args) : _M_f(std::forward(__args)...) {}
GPT:std::make_unique 尝试调用 _FuncImpl 的构造函数时,传递的参数类型不匹配导致的。 确保 _FuncImpl 的构造函数能够正确处理函数指针的引用。通过添加一个额外的构造函数来处理。 能编译通过的代码:https://godbolt.org/z/h4KMKoMYc
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>
---原始邮件--- 发件人: @.> 发送时间: 2024年9月22日(周日) 晚上7:31 收件人: @.>; 抄送: @.***>; 主题: [parallel101/stl1weekend] Function 测试编译报错 (Issue #6)
gcc13.1 -std=c++20
部分报错信息如下: https://godbolt.org/z/KzGoGbdvK error: no matching function for call to 'forward(main()::<lambda(int)>&)' 29 | explicit _FuncImpl(std::in_place_t, _CArgs &&...__args) : _M_f(std::forward(__args)...) {}
GPT:std::make_unique 尝试调用 _FuncImpl 的构造函数时,传递的参数类型不匹配导致的。 确保 _FuncImpl 的构造函数能够正确处理函数指针的引用。通过添加一个额外的构造函数来处理。 能编译通过的代码:https://godbolt.org/z/h4KMKoMYc
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>
嗯,上面只是显示的部分提示报错信息,只显示了一个error,修改为std::forward<_CArgs>(__args)...)后此error没了。 还是有其他error,如下:https://godbolt.org/z/bMs85f4zc error: no matching function for call to 'Function<void(int)>::_FuncImpl<void ()(int)>::_FuncImpl(void ( const&)(int))' 1070 | { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
已修复,请重新pull。
顺便一提,模板报错建议定位到required from here的地方看,才能看明白,不要追到stl头文件最里面,糊弄你的。