Linker error when trying to add constant to iterator
<pre><code>#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

struct foo {
    static const int X = 3;
    static char bar(const string &amp;str) {
        // return str[X]; // this works
        return *(str.begin() + X); // this fails
    }
};

int main() {
    cout &lt;&lt; foo::bar("abcdefg") &lt;&lt; endl;
}
</code></pre>

<p>When compiling this, I get a linker error saying "undefined symbol foo::X". If the previous line is uncommented instead, then it compiles. What makes it different between these two?</p>
