fork download
  1.  
  2. #include <stdio.h>
  3. #include <vector>
  4. using namespace std;
  5. struct Space2
  6. {
  7. struct Vector
  8. {
  9.  
  10. };
  11.  
  12. };
  13. struct Space3
  14. {
  15. struct Vector
  16. {
  17.  
  18. };
  19.  
  20. };
  21.  
  22. template<typename Space,int COUNT>
  23. struct ParticleSystem
  24. {
  25. struct ParticleData;
  26. typedef typename ParticleSystem<Space,0>::ParticleData Particle;
  27. void DumpParticle();
  28. std::vector<Particle> particles;
  29. ParticleSystem()
  30. {
  31. particles.push_back(Particle());
  32. }
  33. };
  34.  
  35. template<> struct ParticleSystem<Space2,0>::ParticleData
  36. {
  37. float orientation;
  38. float invInertia;
  39. ParticleData()
  40. {
  41. orientation = 2.0f ;
  42. invInertia = 3.0f;
  43. }
  44. };
  45.  
  46.  
  47. template<> struct ParticleSystem<Space3,0>::ParticleData
  48. {
  49. float test;
  50. ParticleData()
  51. {
  52. test = 100500.0f;
  53. }
  54. };
  55.  
  56. template<>
  57. void ParticleSystem<Space2,0>::DumpParticle()
  58. {
  59. printf("2: %f %f\n", particles[0].orientation, particles[0].invInertia );
  60. }
  61.  
  62. template<>
  63. void ParticleSystem<Space3,3>::DumpParticle()
  64. {
  65. printf("3: %f\n", particles[0].test);
  66. }
  67. int main()
  68. {
  69. ParticleSystem<Space3,3> p3;
  70. ParticleSystem<Space2,0> p2;
  71. p3.DumpParticle();
  72. p2.DumpParticle();
  73. return 0;
  74. }
  75.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
3: 100500.000000
2: 2.000000 3.000000