Guest User

Untitled

a guest
Jun 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. // probably not the best way but it works
  5.  
  6. typedef unsigned int IDType;
  7.  
  8. class BaseSystem {
  9. public:
  10. static IDType idCounter;
  11. };
  12.  
  13. IDType BaseSystem::idCounter;
  14.  
  15. template <typename Derived>
  16. class System: public BaseSystem {
  17. public:
  18. static IDType id() {
  19. static IDType id = idCounter++;
  20. return id;
  21. }
  22. };
  23.  
  24. int main(){
  25. System<int> s1;
  26. System<char> s2;
  27. System<double> s3;
  28. (void)s1;
  29. (void)s2;
  30. (void)s3;
  31.  
  32. int i1 = System<char>::id();
  33. int i2 = System<float>::id();
  34. int i3 = System<double>::id();
  35.  
  36. // prints "test 0 1 2\n"
  37. printf("test %d %d %d\n", i1, i2, i3);
  38.  
  39. system("pause");
  40. return 0;
  41. }
Add Comment
Please, Sign In to add comment