<p>Can anyone explain why following code won't compile? At least on g++ 4.2.4.</p>

<p>And more interesting, why it will compile when I cast MEMBER to int?</p>

<pre><code>#include &lt;vector&gt;

class Foo {  
public:  
    static const int MEMBER = 1;  
};

int main(){  
    vector&lt;int&gt; v;  
    v.push_back( Foo::MEMBER );       // undefined reference to `Foo::MEMBER'
    v.push_back( (int) Foo::MEMBER ); // OK  
    return 0;
}
</code></pre>

You need to actually define the static member somewhere (after the class definition).  Try this:
```
```
class Foo { /* ... */ };

const int Foo::MEMBER;

int main() { /* ... */ }
```
```
That should get rid of the undefined reference.