Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function 测试编译报错 #6

Open
fengchen321 opened this issue Sep 22, 2024 · 4 comments
Open

Function 测试编译报错 #6

fengchen321 opened this issue Sep 22, 2024 · 4 comments

Comments

@fengchen321
Copy link

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

@archibate
Copy link
Contributor

archibate commented Sep 22, 2024 via email

@fengchen321
Copy link
Author

嗯,上面只是显示的部分提示报错信息,只显示了一个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)...)); }

@archibate
Copy link
Contributor

已修复,请重新pull。

@archibate
Copy link
Contributor

顺便一提,模板报错建议定位到required from here的地方看,才能看明白,不要追到stl头文件最里面,糊弄你的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants