Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ boost shared_ptr as a hash_map key
    primarykey
    data
    text
    <p>I'm making a neural network and wanted to use a hash_map to keep weight references for output neurons for each neuron:</p> <pre><code>class Neuron; //forward declaration was there (sorry I forgot to show it earlier) typedef double WEIGHT; typedef stdext::hash_map&lt;boost::shared_ptr&lt;Neuron&gt;,WEIGHT&gt; NeuronWeightMap; class Neuron { private: NeuronWeightMap m_outputs; //... public: Neuron(); ~Neuron(); //... WEIGHT GetWeight(const boost::shared_ptr&lt;Neuron&gt;&amp; neuron) const { NeuronWeightMap::const_iterator itr = m_outputs.find(neuron); if( itr != m_outputs.end() ) { return itr-&gt;second; } return 0.0f; } }; </code></pre> <p>I realize that I can't use the boost::shared_ptr as the key of a stdext::hash_map, so what would be another suggestion? Are there any work-arounds or is the only option to use a different key or maybe switch to an std::map? Thanks!</p> <p>Here is the errors:</p> <pre><code>1&gt;c:\program files (x86)\microsoft visual studio 8\vc\include\xhash(61) : error C2440: 'type cast' : cannot convert from 'const boost::shared_ptr&lt;T&gt;' to 'size_t' 1&gt; with 1&gt; [ 1&gt; T=Neuron 1&gt; ] 1&gt; No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1&gt; c:\program files (x86)\microsoft visual studio 8\vc\include\xhash(99) : see reference to function template instantiation 'size_t stdext::hash_value&lt;_Kty&gt;(const _Kty &amp;)' being compiled 1&gt; with 1&gt; [ 1&gt; _Kty=boost::shared_ptr&lt;Neuron&gt; 1&gt; ] 1&gt; c:\program files (x86)\microsoft visual studio 8\vc\include\xhash(98) : while compiling class template member function 'size_t stdext::hash_compare&lt;_Kty,_Pr&gt;::operator ()(const _Kty &amp;) const' 1&gt; with 1&gt; [ 1&gt; _Kty=boost::shared_ptr&lt;Neuron&gt;, 1&gt; _Pr=std::less&lt;boost::shared_ptr&lt;Neuron&gt;&gt; 1&gt; ] 1&gt; c:\program files (x86)\microsoft visual studio 8\vc\include\hash_map(80) : see reference to class template instantiation 'stdext::hash_compare&lt;_Kty,_Pr&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; _Kty=boost::shared_ptr&lt;Neuron&gt;, 1&gt; _Pr=std::less&lt;boost::shared_ptr&lt;Neuron&gt;&gt; 1&gt; ] 1&gt; c:\program files (x86)\microsoft visual studio 8\vc\include\xhash(119) : see reference to class template instantiation 'stdext::_Hmap_traits&lt;_Kty,_Ty,_Tr,_Alloc,_Mfl&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; _Kty=boost::shared_ptr&lt;Neuron&gt;, 1&gt; _Ty=common_ns::WEIGHT, 1&gt; _Tr=stdext::hash_compare&lt;boost::shared_ptr&lt;Neuron&gt;,std::less&lt;boost::shared_ptr&lt;Neuron&gt;&gt;&gt;, 1&gt; _Alloc=std::allocator&lt;std::pair&lt;const boost::shared_ptr&lt;Neuron&gt;,common_ns::WEIGHT&gt;&gt;, 1&gt; _Mfl=false 1&gt; ] 1&gt; c:\program files (x86)\microsoft visual studio 8\vc\include\hash_map(90) : see reference to class template instantiation 'stdext::_Hash&lt;_Traits&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; _Traits=stdext::_Hmap_traits&lt;boost::shared_ptr&lt;Neuron&gt;,common_ns::WEIGHT,stdext::hash_compare&lt;boost::shared_ptr&lt;Neuron&gt;,std::less&lt;boost::shared_ptr&lt;Neuron&gt;&gt;&gt;,std::allocator&lt;std::pair&lt;const boost::shared_ptr&lt;Neuron&gt;,common_ns::WEIGHT&gt;&gt;,false&gt; 1&gt; ] 1&gt; FILE_PATH_REMOVED\neuralnet.h(21) : see reference to class template instantiation 'stdext::hash_map&lt;_Kty,_Ty&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; _Kty=boost::shared_ptr&lt;Neuron&gt;, 1&gt; _Ty=common_ns::WEIGHT 1&gt; ] 1&gt;NeuralNet.cpp 1&gt;c:\program files (x86)\microsoft visual studio 8\vc\include\xhash(61) : error C2440: 'type cast' : cannot convert from 'const boost::shared_ptr&lt;T&gt;' to 'size_t' 1&gt; with 1&gt; [ 1&gt; T=Neuron 1&gt; ] 1&gt; No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1&gt; c:\program files (x86)\microsoft visual studio 8\vc\include\xhash(99) : see reference to function template instantiation 'size_t stdext::hash_value&lt;_Kty&gt;(const _Kty &amp;)' being compiled 1&gt; with 1&gt; [ 1&gt; _Kty=boost::shared_ptr&lt;Neuron&gt; 1&gt; ] 1&gt; c:\program files (x86)\microsoft visual studio 8\vc\include\xhash(98) : while compiling class template member function 'size_t stdext::hash_compare&lt;_Kty,_Pr&gt;::operator ()(const _Kty &amp;) const' 1&gt; with 1&gt; [ 1&gt; _Kty=boost::shared_ptr&lt;Neuron&gt;, 1&gt; _Pr=std::less&lt;boost::shared_ptr&lt;Neuron&gt;&gt; 1&gt; ] 1&gt; c:\program files (x86)\microsoft visual studio 8\vc\include\hash_map(80) : see reference to class template instantiation 'stdext::hash_compare&lt;_Kty,_Pr&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; _Kty=boost::shared_ptr&lt;Neuron&gt;, 1&gt; _Pr=std::less&lt;boost::shared_ptr&lt;Neuron&gt;&gt; 1&gt; ] 1&gt; c:\program files (x86)\microsoft visual studio 8\vc\include\xhash(119) : see reference to class template instantiation 'stdext::_Hmap_traits&lt;_Kty,_Ty,_Tr,_Alloc,_Mfl&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; _Kty=boost::shared_ptr&lt;Neuron&gt;, 1&gt; _Ty=common_ns::WEIGHT, 1&gt; _Tr=stdext::hash_compare&lt;boost::shared_ptr&lt;Neuron&gt;,std::less&lt;boost::shared_ptr&lt;Neuron&gt;&gt;&gt;, 1&gt; _Alloc=std::allocator&lt;std::pair&lt;const boost::shared_ptr&lt;Neuron&gt;,common_ns::WEIGHT&gt;&gt;, 1&gt; _Mfl=false 1&gt; ] 1&gt; c:\program files (x86)\microsoft visual studio 8\vc\include\hash_map(90) : see reference to class template instantiation 'stdext::_Hash&lt;_Traits&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; _Traits=stdext::_Hmap_traits&lt;boost::shared_ptr&lt;Neuron&gt;,common_ns::WEIGHT,stdext::hash_compare&lt;boost::shared_ptr&lt;Neuron&gt;,std::less&lt;boost::shared_ptr&lt;Neuron&gt;&gt;&gt;,std::allocator&lt;std::pair&lt;const boost::shared_ptr&lt;Neuron&gt;,common_ns::WEIGHT&gt;&gt;,false&gt; 1&gt; ] 1&gt; FILE_PATH_REMOVED\neuralnet.h(21) : see reference to class template instantiation 'stdext::hash_map&lt;_Kty,_Ty&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; _Kty=boost::shared_ptr&lt;Neuron&gt;, 1&gt; _Ty=common_ns::WEIGHT 1&gt; ] 1&gt;Generating Code... </code></pre>
    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.
    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