You are viewing a single comment's thread. Return to all comments →
thought a will be vector (int) , actually was vector (vector (int)).
int a must be public member, otherwise cannot be accessed from outside the class.
idk why, v[i] = a[i][j] + y.a[i][j] didnt work, changed it to v.push_back(a[i][j] + y.a[i][j]) then it worked.
class Matrix { public: vector<vector<int>> a; Matrix operator+(const Matrix& y) { Matrix z; int n = y.a.size(); int m = y.a[0].size(); for(int i = 0; i < n; i++) { vector<int> v; for(int j = 0; j < m; j++) { v.push_back(a[i][j] + y.a[i][j]); } z.a.push_back(v); } return z; } };
Seems like cookies are disabled on this browser, please enable them to open this website
Operator Overloading
You are viewing a single comment's thread. Return to all comments →
thought a will be vector (int) , actually was vector (vector (int)).
int a must be public member, otherwise cannot be accessed from outside the class.
idk why, v[i] = a[i][j] + y.a[i][j] didnt work, changed it to v.push_back(a[i][j] + y.a[i][j]) then it worked.