-1
    #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 .

user5501265
  • 39
  • 1
  • 8

1 Answers1

1

In your code:

    vector<int> v1;
    v1(x);//no matching call
    ^^^^^^

is a function call, but you dont have function of name v1, also your vector does not overload operator(). You probably wanted:

    vector<int> v1(x);

Also, you need:

v=new datatype[size];

at the begining of your vector(datatype *ptr) constructor.

marcinj
  • 48,511
  • 9
  • 79
  • 100