Undefined reference error for static constexpr member
<p>Consider this code:</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;vector&gt;

struct A {
  static constexpr int kDefaultValue = -1;
  std::vector&lt;int&gt; v;
  A(int n): v(n, A::kDefaultValue) {}
};

int main() {
  A(10);
  return 0;
}
</code></pre>

<p>It fails to link (llvm clang, gcc 4.9, both on OS X):</p>

<pre><code>Undefined symbols for architecture x86_64:
  "A::kDefaultValue", referenced from:
      A::(int) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
</code></pre>

<p>The question is what's wrong with it? It can be fixed by <code>static_cast</code>-ing <code>A::kDefaultValue</code> to <code>int</code>. Or by moving <code>kDefaultValue</code> out of <code>A</code>. Both cases seem to be ugly. Is this another way to make it link?</p>