Thursday 24 April 2014

use of template




#include<iostream>
#include<conio.h>
using namespace std;
int size=3;
template <class x>
class base
{
public:
x *array;
base()
{
for(int j=0;j<3;j++)
{
array[j]=0;
}
}
base(x *a)
{
for(int i=0;i<3;i++)
{
array[i]=a[i];
}
}
x operator *(base &y)
{
x temp;
for(int k=0;k<3;k++)
{
temp=temp+(this->array[k]+y.array[k]);
   }
   return temp;
}
};
int main()
{   int y1[3]={1,2,3};
    int y[3]={4,5,6};
base <int> object;
base <int> object1;
object=y1;
object1=y;
int r=object*object1;
cout<<"R ="<<endl;
cout<<r<<endl;
return 0;
}

No comments:

Post a Comment