title: Arduino C++ passing objects as parameter
body: <p>I'm writing a little Timer class in C++ for Arduino, but I can't pass its instance by reference correctly without being cloned.</p>
  
  <p>Here is the Timer.h :</p>
  
  <pre><code>#ifndef Timer_h
  #define Timer_h
  
  class Timer
  {
      public:
          long t = 0 ;
          long tMax = 60000 ;
  
          Timer() ;
          bool clocked(long n) ;
          void wait(long ms) ;
  } ;
  
  #endif
  </code></pre>
  
  <p>And here the Timer.cpp :</p>
  
  <pre><code>#include "Arduino.h"
  #include "Timer.h"
  
  Timer::Timer() {}
  
  bool Timer::clocked(long n)
  {
      return (t % n) == 0 ;
  }
  
  void Timer::wait(long ms)
  {
      t += ms ;
      delay(ms) ;
  
      Serial.println(t) ;
  
      if (t &gt;= tMax) t = 0 ;
  }
  </code></pre>
  
  <hr>
  
  <p>And here is a main.ino example :</p>
  
  <pre><code>#include "Timer.h"
  #include "ABC.h"
  
  Timer timer = Timer() ;
  ABC abc = ABC() ;
  
  void setup()
  {
      Serial.begin(9600) ;
      abc.setTimer(timer) ;
  }
  
  void loop()
  {
      timer.wait(100) ;
      Serial.println(timer.t) ; // 100
      Serial.println(abc.timer.t) ; // 0, should be 100
  
      timer.wait(50) ;
      abc.timer.wait(100) ;
      Serial.println(timer.t) ; // 150, should be 250
      Serial.println(abc.timer.t) ; // 100, should be 250
  }
  </code></pre>
  
  <p>... with the ABC.h example :</p>
  
  <pre><code>#include "Timer.h"
  
  class ABC
  {
      public:
          Timer timer ;
  
          ABC() ;
          void setTimer(const Timer&amp; tm) ;
  } ;
  </code></pre>
  
  <p>... and ABC.cpp :</p>
  
  <pre><code>#include "Timer.h"
  
  ABC::ABC() {}
  
  void ABC::setTimer(const Timer&amp; tm)
  {
      timer = tm ;
  }
  </code></pre>
  
  <hr>
  
  <p>I surely miss some <code>&amp;</code> or <code>*</code> somewhere, but I can't figure out where.</p>