fork download
  1. #include <vector>
  2. #include <memory>
  3. #include <iostream>
  4.  
  5. struct Vector2f{ float x, y; };
  6. struct Vector3f{ float x, y, z; };
  7. struct Tensor3f{ float xx, xy, xz, yy, yz, zz; };
  8. struct Matrix3x3f{ float data[9]; };
  9. struct Space2
  10. {
  11. typedef Vector2f Vector;
  12. };
  13. struct Space3
  14. {
  15. typedef Vector3f Vector;
  16. };
  17.  
  18.  
  19. //
  20. // Particle.h
  21. // Выносим в отдельный заголовок
  22. //
  23. template<typename T>
  24. struct ParticleData{};
  25.  
  26. template<typename Space>
  27. struct Particle : public ParticleData<Space>
  28. {
  29. typename Space::Vector pos, velocity;
  30. };
  31.  
  32.  
  33. //
  34. // ParticleSystem.h
  35. // Здесь ни какой информации о Particle
  36. //
  37. template<typename Space>
  38. struct ParticleSystem
  39. {
  40. void DumpParticles();
  41.  
  42. struct Implementation;
  43. std::unique_ptr<Implementation> me;
  44. };
  45.  
  46. //
  47. // ParticleSystem.cpp
  48. //
  49. template<>
  50. struct ParticleData<Space2>
  51. {
  52. float orientation;
  53. float invInertia;
  54. };
  55. template<>
  56. struct ParticleSystem<Space2>::Implementation
  57. {
  58. void DumpParticle()
  59. {
  60. printf("%f %f", particles[0].orientation, particles[0].invInertia);
  61. }
  62. std::vector<Particle<Space2>> particles;
  63. };
  64.  
  65. template<typename Space>
  66. void ParticleSystem<Space>::DumpParticles()
  67. {
  68. me->DumpParticle();
  69. }
  70.  
  71. int main()
  72. {
  73. ParticleSystem<Space2> p2;
  74. return 0;
  75. }
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty