title: Arduino: Accessing static variable in the class's static method
body: <p>What I want to do is simply; </p>
  
  <ul>
  <li>Using a static class without instantiating  (preferable a
  Singleton) </li>
  <li>And setting some static class variables within some static
  setter/getter.</li>
  </ul>
  
  <p>It look super easy but I couldn't find any example on the internet wired.
  Whatever I do gives; undefined reference to `Test::_pin' error!
  I does NOT compile.</p>
  
  <p>My class header Test.h:</p>
  
  <pre><code>#ifndef Test_h
  #define Test_h
  #include "Arduino.h"
  
  class Test
  {
      public:
      Test(byte pin);
      static byte getPin();
      static byte _pin;    
  
      private:
  
  };
  #endif
  </code></pre>
  
  <p>My class code Test.cpp:</p>
  
  <pre><code>#include "Test.h"
  
  Test::Test (byte pin) {
      _pin = pin;
  }
  
  byte Test::getPin(){
      return _pin;
  }
  </code></pre>
  
  <p>StaticClassTest.ino:</p>
  
  <pre><code>#include "Test.h"
  
  void setup()
  {
      Test(5);
      Serial.begin(9600);
      Serial.println(Test::getPin(), DEC);
  }
  void loop() { }
  </code></pre>
  
  <p>I've already tried to access _pin with:</p>
  
  <pre><code>byte Test::getPin(){
      return Test::_pin;  // did NOT work, reference error
  }
  </code></pre>
  
  <p>Ideally, _pin should be in private: and accessible by my getPin();
  But as it is impossible to set/get this variable I put in public to have more chance.</p>
  
  <p><strong>What is wrong in this simple context?</strong></p>
  
  <p><strong>How can I set/get this variable in this class?</strong></p>