S
Srinu
Hi,
What is the problem here in this code?
It gives segmentation fault. I found value of size in vector (int *a)
is no more 3. How is this?
==============
#include <iostream>
using namespace std;
class vector
{
int *v;
int size;
public:
vector(int m)
{
v = new int[size = m];
for(int i=0; i<size; i++)
v = 0;
}
vector (int *a)
{
for(int i=0; i<size; i++)
v = a;
}
int operator*(vector &y)
{
int sum = 0;
for(int i=0; i<size; i++)
sum += this -> v * y . v;
return sum;
}
};
int main()
{
int x[3] = {1,2,3};
int y[3] = {4,5,6};
vector v1(3);
vector v2(3);
v1 = x;
v2 = y;
int R = v1 * v2;
cout << "R = " << R;
return 0;
}
Sincerely,
Srinivas Nayak
What is the problem here in this code?
It gives segmentation fault. I found value of size in vector (int *a)
is no more 3. How is this?
==============
#include <iostream>
using namespace std;
class vector
{
int *v;
int size;
public:
vector(int m)
{
v = new int[size = m];
for(int i=0; i<size; i++)
v = 0;
}
vector (int *a)
{
for(int i=0; i<size; i++)
v = a;
}
int operator*(vector &y)
{
int sum = 0;
for(int i=0; i<size; i++)
sum += this -> v * y . v;
return sum;
}
};
int main()
{
int x[3] = {1,2,3};
int y[3] = {4,5,6};
vector v1(3);
vector v2(3);
v1 = x;
v2 = y;
int R = v1 * v2;
cout << "R = " << R;
return 0;
}
Sincerely,
Srinivas Nayak