Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

nphuongsun93

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

  • one year ago
  • one year ago

  • This Question is Closed
  1. nphuongsun93
    Best Response
    You've already chosen the best response.
    Medals 0

    template <class T> class CArray { public: // constructors CArray(unsigned size = DEFAULT_SIZE, T element = static_cast<T>(0)); CArray(const CArray<T>& 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<T> operator=(const CArray<T>& array); T& operator[](unsigned index); const T& operator[](unsigned index) const; CArray<T> operator*=(unsigned scalar); CArray<T> operator*(unsigned scalar) const; CArray<T> operator+(const CArray<T>& array) const; CArray<T> operator+=(const CArray<T>& array); static const int DEFAULT_SIZE = 10; private: // properties T* m_array; unsigned m_size; }; template <class T> ostream & operator<<(ostream & sout, const CArray<T> &arrray); So this is the class. This is what I have for operator+. template <class T> CArray<T> CArray<T>::operator+ (const CArray<T>& array) const { CArray<T> 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 <class T> CArray<T> CArray<T>::operator+=(const CArray<T>& array) { return *this = *this + array; } }

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.