Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- // probably not the best way but it works
- typedef unsigned int IDType;
- class BaseSystem {
- public:
- static IDType idCounter;
- };
- IDType BaseSystem::idCounter;
- template <typename Derived>
- class System: public BaseSystem {
- public:
- static IDType id() {
- static IDType id = idCounter++;
- return id;
- }
- };
- int main(){
- System<int> s1;
- System<char> s2;
- System<double> s3;
- (void)s1;
- (void)s2;
- (void)s3;
- int i1 = System<char>::id();
- int i2 = System<float>::id();
- int i3 = System<double>::id();
- // prints "test 0 1 2\n"
- printf("test %d %d %d\n", i1, i2, i3);
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment