Note that there are some explanatory texts on larger screens.

plurals
  1. PO"cannot access private member'" error only when class has export linkage
    primarykey
    data
    text
    <p>I recently had to change the linkage specification of several classes and ran into a problem. Two of the classes contain a <code>std::map</code> with a <code>std::unique_ptr</code> as the value type. After the linkage was changed the compiler started complaining with "cannot access private member declared in class 'std::unique_ptr&lt;_Ty>'" errors.</p> <p>Anyone know why this only happens when an export specification is supplied or have a solution?</p> <p>Sample Code:</p> <pre><code>#include &lt;map&gt; struct SomeInterface { virtual ~SomeInterface() = 0; }; // This class compiles with no problems struct LocalClass { std::map&lt;int, std::unique_ptr&lt;SomeInterface&gt;&gt; mData; }; // This class fails to compile struct __declspec(dllexport) ExportedClass { std::map&lt;int, std::unique_ptr&lt;SomeInterface&gt;&gt; mData; }; </code></pre> <p>Compiler output:</p> <pre><code>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(163): error C2248: 'std::unique_ptr&lt;_Ty&gt;::unique_ptr' : cannot access private member declared in class 'std::unique_ptr&lt;_Ty&gt;' with [ _Ty=SomeInterface ] c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(2347) : see declaration of 'std::unique_ptr&lt;_Ty&gt;::unique_ptr' with [ _Ty=SomeInterface ] c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(195) : see reference to function template instantiation 'std::_Pair_base&lt;_Ty1,_Ty2&gt;::_Pair_base&lt;const int&amp;,_Ty2&amp;&gt;(_Other1,_Other2)' being compiled with [ _Ty1=const int, _Ty2=std::unique_ptr&lt;SomeInterface&gt;, _Other1=const int &amp;, _Other2=std::unique_ptr&lt;SomeInterface&gt; &amp; ] c:\program files (x86)\microsoft visual studio 10.0\vc\include\xmemory(208) : see reference to function template instantiation 'std::pair&lt;_Ty1,_Ty2&gt;::pair&lt;const _Kty,_Ty&gt;(std::pair&lt;_Ty1,_Ty2&gt; &amp;)' being compiled with [ _Ty1=const int, _Ty2=std::unique_ptr&lt;SomeInterface&gt;, _Kty=int, _Ty=std::unique_ptr&lt;SomeInterface&gt; ] c:\program files (x86)\microsoft visual studio 10.0\vc\include\xmemory(280) : see reference to function template instantiation 'void std::allocator&lt;_Ty&gt;::construct&lt;std::pair&lt;_Ty1,_Ty2&gt;&amp;&gt;(std::pair&lt;_Ty1,_Ty2&gt; *,_Other)' being compiled with [ _Ty=std::pair&lt;const int,std::unique_ptr&lt;SomeInterface&gt;&gt;, _Ty1=const int, _Ty2=std::unique_ptr&lt;SomeInterface&gt;, _Other=std::pair&lt;const int,std::unique_ptr&lt;SomeInterface&gt;&gt; &amp; ] c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(592) : see reference to function template instantiation 'void std::_Cons_val&lt;std::allocator&lt;_Ty&gt;,_Ty,std::pair&lt;_Ty1,_Ty2&gt;&amp;&gt;(_Alloc &amp;,std::pair&lt;_Ty1,_Ty2&gt; *,std::pair&lt;_Ty1,_Ty2&gt;)' being compiled with [ _Ty=std::pair&lt;const int,std::unique_ptr&lt;SomeInterface&gt;&gt;, _Ty1=const int, _Ty2=std::unique_ptr&lt;SomeInterface&gt;, _Alloc=std::allocator&lt;std::pair&lt;const int,std::unique_ptr&lt;SomeInterface&gt;&gt;&gt; ] c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1521) : see reference to function template instantiation 'std::_Tree_nod&lt;_Traits&gt;::_Node *std::_Tree_val&lt;_Traits&gt;::_Buynode&lt;std::pair&lt;_Ty1,_Ty2&gt;&amp;&gt;(_Valty)' being compiled with [ _Traits=std::_Tmap_traits&lt;int,std::unique_ptr&lt;SomeInterface&gt;,std::less&lt;int&gt;,std::allocator&lt;std::pair&lt;const int,std::unique_ptr&lt;SomeInterface&gt;&gt;&gt;,false&gt;, _Ty1=const int, _Ty2=std::unique_ptr&lt;SomeInterface&gt;, _Valty=std::pair&lt;const int,std::unique_ptr&lt;SomeInterface&gt;&gt; &amp; ] c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1516) : while compiling class template member function 'std::_Tree_nod&lt;_Traits&gt;::_Node *std::_Tree&lt;_Traits&gt;::_Copy(std::_Tree_nod&lt;_Traits&gt;::_Node *,std::_Tree_nod&lt;_Traits&gt;::_Node *)' with [ _Traits=std::_Tmap_traits&lt;int,std::unique_ptr&lt;SomeInterface&gt;,std::less&lt;int&gt;,std::allocator&lt;std::pair&lt;const int,std::unique_ptr&lt;SomeInterface&gt;&gt;&gt;,false&gt; ] c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(81) : see reference to class template instantiation 'std::_Tree&lt;_Traits&gt;' being compiled with [ _Traits=std::_Tmap_traits&lt;int,std::unique_ptr&lt;SomeInterface&gt;,std::less&lt;int&gt;,std::allocator&lt;std::pair&lt;const int,std::unique_ptr&lt;SomeInterface&gt;&gt;&gt;,false&gt; ] c:\projects\so\so\so.cpp(18) : see reference to class template instantiation 'std::map&lt;_Kty,_Ty&gt;' being compiled with [ _Kty=int, _Ty=std::unique_ptr&lt;SomeInterface&gt; ] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload