Class template/ partial template specialization

 //class template

//partial template specialization

//use the same class nane for various template

#include<iostream.h>

template<class t1, class t2>

class area

{

t1 a;

t2 b;

public:

area(t1 o1,t2 o2)

{

a=o1;

b=o2;

}

void display()

{

cout<<a<<endl;

cout<<b<<endl;

}

};


template < class t>

class area<t,char>

{

t ob1;

t ob2;

public:

area(t oo1,char c)

{

ob1=oo1;

ob2=int(c);

}

void display()

{

cout<<ob1<<endl;

cout<<ob2<<endl;

}

};



int main(int argc, char *argv[])

{

area<int,int> a1(5,7);

a1.display();


area<int,float>a2(6,7.8);

a2.display();


area<int,char> a3(6,'t');

a3.display();


return 0;

}


Comments

Popular posts from this blog

serial to parallel test with 74c595 and pic mcu

ဆိုလာ စနစ္ရွိ BATTERY AMPACITY အား design ထုတ္တြက္ခ်က္ၿခင္း (1) watt hour ရယူၿခင္း

INTERRUPT_ON_CHANGE_18f4550