In Java you can restrict generics so that the parameter type is only a subclass of a particular class. This allows the generics to know the available functions on the type.
I haven't seen this in C++ with templates. So is there a way to restrict the template type and if not, how does the intellisense know which methods are available for <typename T>
and whether your passed-in type will work for the templated function?
An evolution of the actual type system adopted by C++ is on the way and it's named
concepts
.The new C++1y concepts will probably provide what you are looking for, and since this feature was already planned for C++11 but didn't make it into the final draft, there is a
gcc
fork with an implementation of this concepts .For now "the poor man" solution, if you want to stick with what is given to you by the standard, is to use
type traits
.