title: Initialize static atomic member variable
body: <p>I would like to generate identifiers for a class named <em>order</em> in a threadsafe manner. The code below does not compile. I know that the atomic types do not have copy constructors, and I assume that explains why this code does not work. Does anybody know a way to actually get this code to work? I'm still learning, so please also let me know if I'm on the wrong track (if so, I would appreciate it if you could point me to an alternative approach). Thanks!</p>
  
  <pre><code>#include &lt;atomic&gt;
  #include &lt;iostream&gt;
  
  class order {
  public: 
      order() { id=c.fetch_add(1); }
      int id;
  private:
      static std::atomic&lt;int&gt; c;
  };
  
  std::atomic&lt;int&gt; order::c = std::atomic&lt;int&gt;(0);
  
  int main() {
      order *o1 = new order();
      order *o2 = new order();
      std::cout &lt;&lt; o1-&gt;id &lt;&lt; std::endl; // Expect 0
      std::cout &lt;&lt; o2-&gt;id &lt;&lt; std::endl; // Expect 1
  }
  </code></pre>
  
  <p>Compiling the above results in the following error:</p>
  
  <pre><code>order.cpp:45:51: error: use of deleted function 
          ‘std::atomic&lt;int&gt;::atomic(const std::atomic&lt;int&gt;&amp;)’
  In file included from order.cpp:3:0:
  /usr/include/c++/4.7/atomic:594:7: error: declared here
  </code></pre>