title: How to export class containing a vector of a private struct
body: <p>I have a Class A ( that I would like to export) which contains a vector of a private struct. When compiling the code I have the warning C4251( <a href="http://msdn.microsoft.com/en-us/library/esew7y1w.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/esew7y1w.aspx</a> ). To prevent this warning I did an explicit instantiation. In VS2008 this compiles without any problems but in VS2010 I have following error:</p>
  
  <p>error C2252: an explicit instantiation of a template can only occur at namespace scope</p>
  
  <p>(error C2252:  <a href="http://msdn.microsoft.com/en-us/library/4ds5s2s4(v=vs.100).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/4ds5s2s4(v=vs.100).aspx</a> )</p>
  
  <p>Is there any way to export the class with the vector and keeping the struct private?</p>
  
  <pre><code>class __declspec(dllexport) A
  {
    public:
      A();
      ~A();
  
    private:
      struct StructData
      {
        unsigned int b_;
      };
  
  #if defined(WIN32) &amp;&amp; !defined(__GNUC__)
      template class __declspec(dllexport) std::allocator&lt;StructData&gt;; // explicit instantiation needed to prevent warning C4251
      template class __declspec(dllexport) std::vector&lt;StructData, std::allocator&lt;StructData&gt; &gt;; // explicit instantiation needed to prevent warning C4251
  #endif
      std::vector&lt;StructData&gt; StructDataVector_;
  };
  </code></pre>