Created
September 21, 2012 15:03
-
-
Save yifu/3762012 to your computer and use it in GitHub Desktop.
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 <vector> | |
| #include <iostream> | |
| template <int VAL> | |
| struct another_template_type | |
| { | |
| int dummy; | |
| another_template_type(const int i = 0) : m_i(i) {} | |
| int m_i; | |
| }; | |
| template <int VAL> | |
| class my_template_type | |
| { | |
| public: | |
| int size; | |
| char * ptr; | |
| int method1(const int a); | |
| std::vector<another_template_type<VAL> /*int*/> my_own_vect; | |
| }; | |
| template <int VAL> | |
| int my_template_type<VAL>::method1(const int a) | |
| { | |
| int result = a * a; | |
| result += VAL; | |
| my_own_vect.push_back(result); | |
| } | |
| template <int VAL> | |
| class template_instantier | |
| { | |
| my_template_type<VAL> test; | |
| template_instantier<VAL-1> test2; | |
| public: | |
| int method(); | |
| }; | |
| template <int VAL> | |
| int template_instantier<VAL>::method() | |
| { | |
| const int result = test.method1(VAL + 1); | |
| std::cout << "result is [" << result << "]" << std::endl; | |
| test2.method(); | |
| } | |
| template <> | |
| class template_instantier<0> | |
| { | |
| my_template_type<0> test; | |
| public: | |
| int method() | |
| { | |
| return 42; | |
| } | |
| }; | |
| int main() | |
| { | |
| template_instantier<10000> aa; | |
| aa.method(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment