模拟模板化构造函数。太奇怪了?
我想制作一个模板化构造函数,但我发现我无法显式列出模板参数,所以我不得不寻找另一个解决方案。这就是我所做的:
ResourceManager rm = ResourceManager::Create<physfs::ifstream>();
您还有其他想法如何在构建时实现这一目标吗?或者这是一个足够好的解决方案(不太奇怪)?
注意:我使用移动构造函数(这是唯一的公共构造函数)来避免创建不必要的类副本。
I wanted to make a templated constructor, but I found I had no way of explicitly listing the template arguments, so I had to find another solution. Here's what I did:
ResourceManager rm = ResourceManager::Create<physfs::ifstream>();
Do you have any other ideas how I might achieve this upon construction? or is this a good enough solution (not too odd)?
Note: I'm using a move constructor (which is the only public constructor) to avoid creating unnecessary copies of the class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的代码应该可以。为了改进设计,请考虑在(例如)ResourceManager 中声明类型,并根据需要使用它来限定构造函数。
I think your code should do. To improve design, consider declaring types inside (for instance) ResourceManager and using that to qualify the constructors, as needed.