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

自动注册工厂出现空悬引用 #23

Open
xiaolanpingguo opened this issue Jul 14, 2018 · 1 comment
Open

自动注册工厂出现空悬引用 #23

xiaolanpingguo opened this issue Jul 14, 2018 · 1 comment

Comments

@xiaolanpingguo
Copy link

我在项目中遇到的情况,在self_register_factory.hpp中,

template<typename... Args>
register_t(const std::string& key, Args... args)
{
factory::get().map_.emplace(key, [&] { return new T(args...); });
}

这里的lambda表达式应该按值("=")来捕获,如果采用引用捕获的话,之后在调用
factory::get().produce生产产品的时候可能会出现空悬引用

@qicosmos
Copy link
Owner

是参数失效了,要改一下。

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