Default Data Types as Parameters to Generic Classes






This video tutorial explains how to specify default datatypes during the generic class definition.
You are gonna learn what happens when we specify the default datatypes with generic class definition, how we can create objects from the generic class when it has default datatypes specified, in which order we have to pass default parameters to generic class definition in detail with example.

source code for this tutorial

#include <iostream>

using namespace std;

template <class Type1 , class Type2 = int >class MyClass{

Type1 p1;
Type2 p2;

public:
    MyClass(Type1 x, Type2 y){
    p1 = x;
    p2 = y;
    }
    void whatYouGot(){
    cout << "i got "<<p1<<" and "<<p2<<endl;
    }

};

int main()
{
MyClass <string> ob1("anil",24);
MyClass <float> ob2(22.36,55);
MyClass <int,string> ob3(21,"anjali");

ob1.whatYouGot();
ob2.whatYouGot();
ob3.whatYouGot();

    return 0;
}