How to access static members of a class?
<p>I started to learn C++ and Qt hopefully. but sometimes the simplest code that I pasted from a book becomes full of errors. I'm using g++4.4.2 on ubuntu 10.04 with QtCreator IDE. Is there a difference between g++ compiler syntax and other copmpilers? for example when I try to access static members always something goes wrong.</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
class A
{
   public:
      static int x;
      static int getX(){return x;}
};
int main()
{
   int A::x = 100; // error: invalid use of qualified-name 'A::x'
   cout&lt;&lt;A::getX(); // error: : undefined reference to 'A::x'
   return 0;
}
</code></pre>

<p>I think it's exactly same as declared <a href="http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr038.htm" rel="nofollow">here</a> and <a href="http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr038.htm" rel="nofollow">here</a> (isn't?). So what's wrong with above code?</p>
