When dealing with template functions, there's often no need to explicitly define template parameters, but you can rely on automatic type deduction mechanism. A simplest illustration:

#include <typeinfo.h>

template<typename T>
void print(const T& t) {
   std::cout << t << " \"" << typeid(T).name() << '\"' << std::endl;

void test(void) {

You will get the following output:

10 "int"
hello "char const [6]"
hell "char const [5]"

BTW, notice that the types of "hello" and "hell" are different (and are not char const *)

Last edited Nov 29, 2007 at 6:13 PM by migo, version 2


No comments yet.