Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 2
    or just use std::vector<T> Commented Apr 5, 2018 at 16:01
  • 1
    The only drawback is that different template instantiations are different types, so they wouldn't be able to, for example, store instances of both types inside the same container, though it's not clear from the original post whether this is something they would really need to do. Commented Apr 5, 2018 at 16:06
  • @SeanBurton: it appeared OP was using inheritance to factor out common implementation. Nothing in the question indicated that the variants had to inherit some common base type. Commented Apr 7, 2018 at 7:50
  • @kevin Thanks for the advice. This code is so clean! But if I have to write specialization for integer and double separately, would that be similar to writing two separate classes without template? would template still have advantage in that case? Is it correct that I should use template when I have different Ts that can share same class? Commented Apr 7, 2018 at 19:20
  • @SeanBurton and Caleth, I may have oversimplified my case, and it may not be clear. Thanks for reminding me that different instantiations are different types. It would be great in my situation to put them in the same container, but I guess I can' do that. Commented Apr 7, 2018 at 19:26