Ace school

with brainly

  • Get help from millions of students
  • Learn from experts with step-by-step explanations
  • Level-up by helping others

A community for students.

C++ question. I need help writing a function (operator+) that concatenates arrays for a class. More info inside.

Computer Science
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

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; } }

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question