We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/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; }
};
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
C++ Class Templates
You are viewing a single comment's thread. Return to all 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; } };