Question: How do I use the + overload operator in C++ to add two arrays? Hi I'm trying to use the overload operator to add 2
How do I use the + overload operator in C++ to add two arrays?
Hi I'm trying to use the overload operator to add 2 arrays, here's the snippet from the code I'm writing now and its giving a blank when I make the two objects and add them together with a third
class Sally { private: int arr[10][10]; int x, y; public: mat operator +(mat); };
Sally Sally::operator+(Sally sally2) {
Sally brandNew; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { brandNew[i][j].arr = arr[i][j] + sally2.arr[i][j]; } }
return (brandNew); }
//code to make array and read
Sally obj1, obj2, obj3
obj3 = obj1 + obj2;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
