How to create explicit specializations of generic class in C++?

Creating explicit specializations for a class is very helpful when you are defining some specific classes. Here’s how to create an explicit specialization of a generic class:

For Example:

template <class T> class test {

T i;


test(T j) {

i = j;


T geti() { return i; }


template <> class test<int> {

int i;


test(int j) {

i = j+j;


int geti() { return i; }


Leave a Reply