fork(2) download
  1. #include <iostream>
  2.  
  3. inline int getLastId() { static int last{0}; return last++; }
  4.  
  5. template<typename T> struct IdInfo { static int id; };
  6. template<typename T> int IdInfo<T>::id{getLastId()};
  7.  
  8. struct Type00 { };
  9. struct Type01 { };
  10. struct Type02 { };
  11.  
  12. int main(void)
  13. {
  14. using namespace std;
  15.  
  16. cout << IdInfo<Type00>::id << "\n"
  17. << IdInfo<Type01>::id << "\n"
  18. << IdInfo<Type02>::id << endl;
  19.  
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
0
1
2