title: Overloaded Methods in a class (arduino)
body: <p>Header code</p>
  
  <pre><code>/*
   * MngCommunication.h
   *
   *  Created on: 26 gen 2017
   *      Author: Giuliano
   */
  
  #ifndef _MNGCOMMUNICATION_H_
  #define _MNGCOMMUNICATION_H_
  
  // ------------------------- N.B. MngCommunication is a Singleton     class!!! ----------------------------
  #if (ARDUINO &lt;  100)
  #include &lt;WProgram.h&gt;
  #else
  #include &lt;Arduino.h&gt;
  #endif
  
  class MngCommunication
  {
  public:
      static MngCommunication* getInstance();
  
  
      size_t LogLine(const __FlashStringHelper *ifsh, boolean end=false);
      size_t LogLine(const String &amp;str, boolean end=false);
      size_t LogLine(const char str[], boolean end=false);
      size_t LogLine(const unsigned char n, boolean end=false);
      size_t LogLine(const int n, boolean end=false);
      size_t LogLine(const unsigned int n, boolean end=false);
      size_t LogLine(const long n, boolean end=false);
      size_t LogLine(const unsigned long n, boolean end=false);
      size_t LogLine(const double n, boolean end=false);
      size_t LogLine(const Printable&amp;str, boolean end=false);
  
  protected:
      static MngCommunication* _inst_;
      MngCommunication();
  };
  
  #endif /* MNGCOMMUNICATION_MNGCOMMUNICATION_H_ */
  </code></pre>
  
  <p>C++ code</p>
  
  <pre><code>/*
   * MngCommunication.cpp
   *
   *  Created on: 26 gen 2017
   *      Author: Giuliano
   */
  
  #include &lt;string.h&gt;
  #include "MngCommunication.h"
  
  
  MngCommunication* MngCommunication::_inst_ = NULL;
  
  
  MngCommunication::MngCommunication()
  {
      Serial.begin(57600);
  
  }
  
  
  MngCommunication* MngCommunication::getInstance()
  {
      if (_inst_ == NULL) _inst_ = new MngCommunication;
  
      return _inst_;
  }
  
  //--------------------------------------------------------------------
  //--------------------------------------------------------------------
  // ------------------------ LOGGING FUNCTION -------------------------
  //--------------------------------------------------------------------
  //--------------------------------------------------------------------
  boolean started=false;
  
  inline size_t startLine(void)
  {
      static char timebuffer[8];
      size_t sz = 0;
  
      sprintf(timebuffer,"%08lu", millis());
  
      sz += Serial.print("#L-");
      sz += Serial.print(timebuffer);
      sz += Serial.print("-");
      started=true;
      return sz;
  
  }
  
  inline size_t endline(void)
  {
      started = false;
      return Serial.write("\r\n");
  }
  
  size_t MngCommunication::LogLine(const __FlashStringHelper *ifsh, boolean end)
  {
      size_t sz=0;
      if (!started)
      {
      sz += startLine();
      started = true;
      }
  
      sz += Serial.print(ifsh);
  
      if (end)
      {
          sz += endline();
      }
  
  
      return sz;
  }
  
  size_t MngCommunication::LogLine(const String &amp;str, boolean end)
  {
      size_t sz=0;
      if (!started)
      {
          sz += startLine();
          started = true;
      }
  
      sz += Serial.print(str);
  
      if (end)
      {
          sz += endline();
      }
  
      return sz;
  }
  
  
  size_t MngCommunication::LogLine(const char str[], boolean end)
  {
      size_t sz=0;
      if (!started)
      {
          sz += startLine();
          started = true;
      }
  
      sz += Serial.print(str);
  
      if (end)
      {
          sz += endline();
      }
  
      return sz;
  }
  
  
  
  
  
  size_t MngCommunication::LogLine(const unsigned char n, boolean end)
  {
      return LogLine((unsigned long) n, end);
  }
  
  
  size_t MngCommunication::LogLine(const int n, boolean end)
  {
      return LogLine((long) n, end);
  }
  
  size_t MngCommunication::LogLine(const unsigned int n, boolean end)
  {
      return LogLine((unsigned long) n, end);
  }
  
  
  size_t MngCommunication::LogLine(const long n, boolean end)
  {
      size_t sz=0;
      if (!started)
      {
          sz += startLine();
          started = true;
      }
  
      sz += Serial.print(n);
  
      if (end)
      {
          sz += endline();
      }
  
      return sz;
   }
  
   size_t MngCommunication::LogLine(const unsigned long n, boolean end)
   {
      size_t sz=0;
      if (!started)
      {
          sz += startLine();
          started = true;
      }
  
      sz += Serial.print(n);
  
      if (end)
      {
          sz += endline();
      }
  
      return sz;
  }
  
  
  
  size_t MngCommunication::LogLine(const double n, boolean end)
  {
      size_t sz=0;
      if (!started)
      {
          sz += startLine();
          started = true;
       }
  
       sz += Serial.print(n);
  
      if (end)
      {
           sz += endline();
      }
  
      return sz;
  }
  
  size_t MngCommunication::LogLine(const Printable&amp;str, boolean end)
  {
      size_t sz=0;
      if (!started)
      {
          sz += startLine();
          started = true;
      }
  
      sz += Serial.print(str);
  
      if (end)
      {
          sz += endline();
      }
  
      return sz;
  }
  </code></pre>
  
  <p>If I use <code>LogLine()</code> function with string or char buffers, all is OK. e.g.:</p>
  
  <pre><code>MngCommunication* Comm;
  
  Comm = MngCommunication::getInstance();
  Comm.LogLine("this ");
  Comm.LogLine("is ");
  Comm.LogLine("a ");
  Comm.LogLine("test!!! ", true);
  </code></pre>
  
  <p>The strange is the call with number:
  if i call  <code>LogLine()</code> with number e.g.:</p>
  
  <pre><code>MngCommunication* Comm;
  
  Comm = MngCommunication::getInstance();
  Comm.LogLine(millis());
  </code></pre>
  
  <p>code execution is OK. but a second call, with number or string, reboot Arduino. The same is if i call the function first with string and then with number. e.g.:</p>
  
  <pre><code>MngCommunication* Comm;
  
  Comm = MngCommunication::getInstance();
  Comm.LogLine("this ");
  Comm.LogLine("is ");
  Comm.LogLine("a ");
  Comm.LogLine("test!!! ");
  
  Comm.LogLine("time= ");
  Comm.LogLine(mills());
  </code></pre>