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>
  23. struct ParticleSystem
  24. {
  25. struct ParticleData;
  26. void DumpParticle() {}
  27. std::vector<ParticleData> particles;
  28. ParticleSystem()
  29. {
  30. particles.push_back(ParticleData());
  31. }
  32. };
  33.  
  34.  
  35. template<> struct ParticleSystem<Space2>::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>::ParticleData
  48. {
  49. float test;
  50. ParticleData()
  51. {
  52. test = 100500.0f;
  53. }
  54. };
  55.  
  56. template<>
  57. void ParticleSystem<Space2>::DumpParticle()
  58. {
  59. printf("2: %f %f\n", particles[0].orientation, particles[0].invInertia );
  60. }
  61.  
  62. template<>
  63. void ParticleSystem<Space3>::DumpParticle()
  64. {
  65. printf("3: %f\n", particles[0].test);
  66. }
  67.  
  68. int main()
  69. {
  70. ParticleSystem<Space3> p3;
  71. ParticleSystem<Space2> p2;
  72. p3.DumpParticle();
  73. p2.DumpParticle();
  74. return 0;
  75. }
  76.  
  77.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
3: 100500.000000
2: 2.000000 3.000000