From the journal
"An instantiated object of a templated class is called a specialization; the term specialization is useful to remember because it reminds us that the original class is a generic class, whereas a specific instantiation of a class is specialized for a single datatype (although it is possible to template multiple types)."
An instantiated object of a templated class has no special name. The process of the compiler making a class for a given template parameter is called template instantiation, much like object instantiation is when an object is made from a class, template instantiation is when a class is created by the compiler for a given template parameter.
Template specialization is when a template is made different than the general case. There are many uses for this, but they are generally fairly complex.
Code:#include <iostream> #include <typeinfo> #include <string> using namespace std; template <class T> void func(const T& arg) { std::cout << "General template for type " << typeid(arg).name() <<" " << arg << std::endl; } template <> void func<int>(const int& arg) { std::cout << "Specialized template for type int " << arg << endl; } int main(int argc, char *argv[]) { func('a'); func(true); func(212.3f); func(21L); func(3.131459265); func(20); func("asdf"); func(string("asdf")); return 0; }



LinkBack URL
About LinkBacks


