#include<iostream>
using namespace std;
const int size=4;
template<class datatype>
class vector
{
datatype *v;
public:
vector()
{
v=new datatype[size];
for(int i=0;i<size;i++)
{
v[i]=0;//initilaizing vector
}
}
vector(datatype *ptr)
{
//v=ptr;
for(int i=0;i<size;i++)
{
v[i]=ptr[i];
}
}
datatype operator*(vector &obj)
{
datatype sum=0;
for(int i=0;i<size;i++)
{
sum+=(this)->v[i] * obj.v[i];
}
return sum;
}
};
int main()
{
int x[4]={1,2,9,11};
int y[4]={4,7,7,4};
vector<int> v1;
v1(x);//no matching call
vector<int> v2;
v2(y);//no matching call
// v1(x);
// v2(y);
int total=v1*v2;
cout<<"Total of v1*v2="<<total<<endl;
}
the constructor which in which i am passing integer array x an y is giving me following error.
error: no match for call to '(vector) (int [4])'.
error: no match for call to (vector) (int [4]).there is some problem with assigning array to pointer.
can anyone correct my code .