fork(1) download
  1. class MotorStatic;
  2. // Kapselt die Laufzeit-Daten, die im RAM landen sollen
  3. class MotorRuntime {
  4. friend class MotorStatic;
  5. public:
  6. constexpr MotorRuntime (int x, int y, int z) : m_x (x), m_y (y), m_z (z) {}
  7. protected:
  8. int m_x, m_y, m_z;
  9. };
  10.  
  11. // Kapselt die fixen Parameter, die im Flash landen sollen
  12. class MotorStatic {
  13. public:
  14. constexpr MotorStatic (int a, int b, int c, MotorRuntime& runtime) : m_a (a), m_b (b), m_c (c), m_runtime (runtime) {}
  15. void regelalgorithmus () const {
  16. m_runtime.m_x += m_a;
  17. }
  18. protected:
  19. int m_a, m_b, m_c;
  20. MotorRuntime& m_runtime;
  21. };
  22.  
  23. MotorRuntime theMotorRuntime [3] { { 1, 2, 3 }, {4, 5, 6}, {7, 8, 9}};
  24. constexpr MotorStatic theMotorStatic [3] { { 1, 2, 3, theMotorRuntime [0]},
  25. { 4, 5, 6, theMotorRuntime [2]},
  26. { 7, 8, 9, theMotorRuntime [3]}};
  27.  
  28. int main() {
  29. for (const MotorStatic& ms : theMotorStatic) {
  30. ms.regelalgorithmus ();
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty