c++ Write a simple templated dummy class MyTemplate Give it some functionality,
ID: 3744612 • Letter: C
Question
c++
Write a simple templated dummy class MyTemplate Give it some functionality, e.g: - a parameterized constructor that initializes some private data member my_data_ of type ItemType - an accessor member function getData() Write a main() function that initializes different MyTemplate objects with different types (e.g. int, string) and makes calls to their accessor member functions to observe their behavior. E.g: MyTemplate intObject; cout << intObject.getData() << endl; Make sure you understand and don’t have problems with multi-file compilation using templates
The declaration, implementation, and main file should be in different files (like the instructions say multiple file).
Thank you.
Explanation / Answer
#include #include using namespace std; template class MyTemplate { private: ItemType my_data_; public: MyTemplate(ItemType data) { my_data_ = data; } ItemType getData() { return my_data_; } }; int main() { MyTemplate intObject(5); coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.