title: Initializing static constexpr variables and classes inside a struct
body: <p>Here is my working code example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template&lt;typename B&gt;
  class b {
  public:
      int y;
  
      constexpr b(int x) : y(x) {
  
      }
  
      constexpr void sayhi() {
          std::cout &lt;&lt; "hi" &lt;&lt; std::endl;
      }
  };
  
  
  
  template&lt;int x&gt;
  struct A {
      static constexpr b&lt;int&gt; bee = x;
      static constexpr int y = x;         // this one is fine and usable already, I don't have to do something like what I did on member bee
  
      inline static void sayhi() {
          std::cout &lt;&lt; y &lt;&lt; std::endl;
      }
  };
  
  template&lt;int x&gt;
  constexpr b&lt;int&gt; A&lt;x&gt;::bee;        // why do I have to do something like this, it will cause errors if I don't.
  
  int main(int argc, char** argv) {
      A&lt;30&gt;::bee.sayhi();             // works fine
      A&lt;30&gt;::sayhi();                 // works fine
  
      return 0;
  }
  </code></pre>
  
  <p>What my code does is simple, I have template struct <code>A</code> that has two static variables, namely a <code>static constexpr int y</code> and a <code>static constexpr b&lt;int&gt; bee = x;</code>. My template struct <code>A</code> will get the value of the argument which will be copied by <code>x</code> from the template parameter. My question is: how come when it comes to classes, I have to initialize the class by doing something like this:</p>
  
  <pre><code>template&lt;int x&gt;
  constexpr b&lt;int&gt; A&lt;x&gt;::bee; 
  </code></pre>
  
  <p>If I don't use the code above, I get the <code>undefined</code> reference error. Wherein the int is already fine and accessible just from doing something like:</p>
  
  <pre><code>static constexpr int y = x;    
  </code></pre>
  
  <p>I am concerned why I don't have to forward declare it anymore. </p>