3

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.

Paul Manta
  • 30,618
  • 31
  • 128
  • 208
  • The answer to [this question of mine](http://stackoverflow.com/questions/6230448/is-it-possible-to-have-a-templated-constructor-like-templateclass-t-x) should also answer your question. (Can't delete the comment because the mobile view of SO won't let me...) – Xeo Oct 23 '11 at 18:46
  • @Xeo Yes, I know of that limitation. I was wondering what workarounds there are. – Paul Manta Oct 23 '11 at 18:47
  • I've seen this before. The only way to bypass it that I know of is to pass an instance of the templated type to thee constructor, so the compiler automatically deduces the type. Or use a std::constant_integer for template parameters. – Mooing Duck Oct 23 '11 at 18:48
  • @Mooing I've never seen `std::constant_integer` before. What header is it from? (Googling didn't turn out anything useful.) – Paul Manta Oct 23 '11 at 18:51
  • 2
    It's actually `integral_constant`. I'm not sure where it is officially stored, but `type_traits` works for me. It's a TR1 addition. – Dennis Zickefoose Oct 23 '11 at 18:54

1 Answers1

1

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.

CapelliC
  • 59,646
  • 5
  • 47
  • 90