Note that there are some explanatory texts on larger screens.

plurals
  1. POError C2562 when using (and exporting) boost::shared_ptr<T>
    primarykey
    data
    text
    <p>Hi fellow programmers,</p> <p>I'm creating a C++ DLL library in which I'm using boost's (1.55) shared_ptr. Howewer, when I'm compiling the project with Visual Studio 2013 a bunch of wild errors C2562 appears:</p> <pre><code>Error 1 error C2562: 'boost::shared_ptr&lt;MEngine::i18n::ITranslationSource&gt;::operator []' : 'void' function returning a value f:\developer\cplus\lib\boost_1_55_0\boost\smart_ptr\shared_ptr.hpp 663 1 MEngine Error 2 error C2562: 'boost::shared_ptr&lt;MEngine::i18n::ITranslationSource&gt;::operator []' : 'void' function returning a value f:\developer\cplus\lib\boost_1_55_0\boost\smart_ptr\shared_ptr.hpp 663 1 MEngine Error 3 error C2562: 'boost::shared_ptr&lt;MEngine::Object::GameObject&gt;::operator []' : 'void' function returning a value f:\developer\cplus\lib\boost_1_55_0\boost\smart_ptr\shared_ptr.hpp 663 1 MEngine Error 4 error C2562: 'boost::shared_ptr&lt;MEngine::Object::GameObject&gt;::operator []' : 'void' function returning a value f:\developer\cplus\lib\boost_1_55_0\boost\smart_ptr\shared_ptr.hpp 663 1 MEngine Error 5 error C2562: 'boost::shared_ptr&lt;MEngine::Object::GameObject&gt;::operator []' : 'void' function returning a value f:\developer\cplus\lib\boost_1_55_0\boost\smart_ptr\shared_ptr.hpp 663 1 MEngine Error 6 error C2562: 'boost::shared_ptr&lt;MEngine::i18n::ITranslationSource&gt;::operator []' : 'void' function returning a value f:\developer\cplus\lib\boost_1_55_0\boost\smart_ptr\shared_ptr.hpp 663 1 MEngine Error 7 error C2562: 'boost::shared_ptr&lt;MEngine::i18n::ITranslationSource&gt;::operator []' : 'void' function returning a value f:\developer\cplus\lib\boost_1_55_0\boost\smart_ptr\shared_ptr.hpp 663 1 MEngine Error 8 error C2562: 'boost::shared_ptr&lt;MEngine::i18n::ITranslationSource&gt;::operator []' : 'void' function returning a value f:\developer\cplus\lib\boost_1_55_0\boost\smart_ptr\shared_ptr.hpp 663 1 MEngine </code></pre> <p>As you can see there's the same error for every shared_ptr template instantiation. The thing is I never use that operator, so shouldn't the code for it not be generated?</p> <p>In that case it is and it is completely understandable why that error appears, because in the shared_ptr.h there is this:</p> <pre><code>typename boost::detail::sp_array_access&lt; T &gt;::type operator[] ( std::ptrdiff_t i ) const { BOOST_ASSERT( px != 0 ); BOOST_ASSERT( i &gt;= 0 &amp;&amp; ( i &lt; boost::detail::sp_extent&lt; T &gt;::value || boost::detail::sp_extent&lt; T &gt;::value == 0 ) ); return px[ i ]; } </code></pre> <p>and that:</p> <pre><code>template&lt; class T &gt; struct sp_array_access { typedef void type; }; ... template&lt; class T &gt; struct sp_array_access&lt; T[] &gt; { typedef T &amp; type; }; ... </code></pre> <p>Which means that for smart_ptr&lt; T > if T is not an array the return type of operator[] is void, so the code for the operator will not compile.</p> <p>So the real problem is (I think) that the code for the operator is generated but it shouldn't. I need to export the shared_ptr to my DLL's interface and since it's a template I'm using this to instantiate and export it:</p> <pre><code>EXPIMP_TEMPLATE template class MENGINE_API boost::shared_ptr&lt;MEngine::i18n::ITranslationSource&gt;; </code></pre> <p>where the macros are (pretty standard):</p> <pre><code>#ifdef MENGINE_EXPORTS #define MENGINE_API _declspec(dllexport) #define EXPIMP_TEMPLATE #else #define MENGINE_API _declspec(dllimport) #define EXPIMP_TEMPLATE extern #endif </code></pre> <p>Does the export statement which I'm using causes the generation of everything in the template? If this is true then how can I get past that and achieve the export?</p> <p>Apologies for my English :) Correcting me is also much appreciated as I'm willing to learn :)</p>
    singulars
    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