C++ Class Templates

  • + 0 comments

    /Write the class AddElements here/ template class AddElements { T element; public: AddElements(T arg) : element(arg) {} T add(const T& other) { return element + other; } };

    // specialization for string: use concatenate() template <> class AddElements { string element; public: AddElements(string arg) : element(std::move(arg)) {} string concatenate(const string& other) { return element + other; } };