Explicit Specialization of Generic Class





This video tutorial explains the explicit specialization of generic class i.e overriding the generic class for a specific version of it in c++ programming.
You are gonna learn what happens when we do explicit specialization on a generic class, how to define a class for a datatype which will override the generic class for that datatype, what is the syntax to denote explicit specialization of a class in detail with example.

source code for this tutorial

#include <iostream>

using namespace std;

template <class Type> class MyClass{
Type p1;
public:
    MyClass(Type p){
        cout << "from the generic class conbstructor"<<endl;
    p1 = p;

    }
    void whatYouGot(){
    cout << p1<<endl;
    }

};

template <> class MyClass <int>{
int p1;
public:
    MyClass(int p){
    p1 = p;
     cout << "from the specific integer version class conbstructor"<<endl;

    }
    void whatYouGot(){
    cout << p1<<endl;
    }


};

int main()
{
    MyClass <string> ob1("anil");
    MyClass <int> ob2(22);
    ob1.whatYouGot();
    ob2.whatYouGot();
    return 0;
}