<<< Example of STL containers | Index | STL Containers >>> |
Template function calls normally ommit template parameters,
because the typenames can be absorbed directly from the actual function call parameters.
However, template parameters of functions may also be specified by the programmer:
#include <cassert>
#include <algorithm>
using namespace std;
int main (int argc, char* argv[])
{
int one = 1;
int two = 2;
swap< int >( one, two ); // explicit template param
swap( one, two ); // implicit template param
assert( one == 1 );
assert( two == 2 );
return 0;
}
Because swap expects both arguments to be of the same type, it needs only one template parameter.
<<< Example of STL containers | Index | STL Containers >>> |