anonymous
  • anonymous
C++ question. I need help writing a function (operator+) that concatenates arrays for a class. More info inside.
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
template class CArray { public: // constructors CArray(unsigned size = DEFAULT_SIZE, T element = static_cast(0)); CArray(const CArray& ar); // destructor ~CArray() { if(m_array != nullptr) delete[] m_array; } unsigned getSize() const { return m_size; } void print(ostream& sout, char delimiter = ' ') const; // operators CArray operator=(const CArray& array); T& operator[](unsigned index); const T& operator[](unsigned index) const; CArray operator*=(unsigned scalar); CArray operator*(unsigned scalar) const; CArray operator+(const CArray& array) const; CArray operator+=(const CArray& array); static const int DEFAULT_SIZE = 10; private: // properties T* m_array; unsigned m_size; }; template ostream & operator<<(ostream & sout, const CArray &arrray); So this is the class. This is what I have for operator+. template CArray CArray::operator+ (const CArray& array) const { CArray temp(*this); temp.m_size = temp.m_size + array.m_size; for (unsigned i = 0; i < array.m_size; i++) { temp.m_array[m_size+i] = array.m_array[i]; } return temp; } template CArray CArray::operator+=(const CArray& array) { return *this = *this + array; } }

Looking for something else?

Not the answer you are looking for? Search for more explanations.