Created
November 9, 2018 09:14
-
-
Save yongjun823/e1d15eb05412bfe4bd37d18e191d657a to your computer and use it in GitHub Desktop.
c++ template with class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///// | |
| #include <iostream> | |
| #include "arr.h" | |
| template class Arrayy<int>; | |
| template class Arrayy<double>; | |
| template <typename T> | |
| Arrayy<T>::Arrayy() { | |
| } | |
| template <typename T> | |
| void Arrayy<T>::printT(T x) { | |
| std:: cout << x << std::endl; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename T> | |
| class Arrayy { | |
| public: | |
| Arrayy(); | |
| void printT(T x); | |
| private: | |
| T* mass; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include "arr.h" | |
| int main() { | |
| Arrayy<int> list1; | |
| Arrayy<double> list2; | |
| list1.printT(10); | |
| list2.printT(10.2); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment