Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing a vector which is a value in a map to run the equality operator on it with another vector
    primarykey
    data
    text
    <p>I have a vector that is made up of maps which have the following type definition:</p> <p><code>std::map&lt; int, std::vector&lt;int&gt; &gt;</code></p> <p>Thus, the definition of the vector itself is: </p> <p><code>std::vector&lt; std::map&lt; int, std::vector&lt;int&gt; &gt; &gt;</code></p> <p>Now I am creating a vector of integers and inserting it in a map with an integer key and adding the map itself to the outer vector:</p> <pre><code> std::map&lt;int, std::vector&lt;int&gt; &gt; vDescriptorAtom; vDescriptorAtom.insert( std::make_pair(498, vListOfIds) ); messageDescriptorVector.push_back( vDescriptorAtom ); </code></pre> <p>Where vListOfIds itself is a vector of integers. </p> <p>At a later stage I want to extract the inner vector and compare with another vector that I possess. I was under the impression that I can easily use the <code>==</code> operator between the two vectors to do the comparison. But I am having some trouble doing this. </p> <p>I tried:</p> <pre><code> for ( int i = 0 ; i &lt;= messageDescriptorVector.size(); i++ ) { if ( current_tag_stack == (messageDescriptorVector.at(i))-&gt;second ) { vFoundMatchingDescriptor = true; break; } } </code></pre> <p>Note that current_tag_stack has the following definition: </p> <pre><code>std::vector&lt;int&gt; current_tag_stack; </code></pre> <p>But I am getting this error: </p> <pre><code>base operand of â-&gt;â has non-pointer type âstd::map&lt;int, std::vector&lt;int, std::allocator&lt;int&gt; &gt;, std::less&lt;int&gt;, std::allocator&lt;std::pair&lt;const int, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt; &gt; &gt;â </code></pre> <p>What am I doing wrong ? </p> <p><strong>EDIT</strong></p> <p>As suggested by a comment, I tried to access the vector that I have stored inside the map as: <code>messageDescriptorVector.at(i).second</code> but it is giving me this error: <code>âclass std::map&lt;int, std::vector&lt;int, std::allocator&lt;int&gt; &gt;, std::less&lt;int&gt;, std::allocator&lt;std::pair&lt;const int, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt; &gt; &gt;â has no member named âsecondâ </code></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