confused on how to used pointers and vector pointers
<p>I am confused on how to use pointers and vector pointers to perform the correct operation. </p>

<p>I want to pass elements of vector <code>Vec</code> to struct function <code>updateHeap</code>. <code>updateHeap</code> modifies the value of these members. I can't quite achieve this result with my code below. I have commented sections in my code to explain my problem better. </p>

<pre><code>#include &lt;vector&gt;
#include &lt;iostream&gt;

struct A
{
    A() : hLoc(100){}
    A(int av, int bv):a(av),b(bv),hLoc(100){}

    int a, b;
    int hLoc;
};

struct Heap
{
    Heap() : heapMembers(new std::vector&lt;A&gt;) {}

    Heap(std::vector&lt;A&gt; *members) : heapMembers(members) {}

    void updateHeap(unsigned int idx)
    {
        (*heapMembers)[idx].a*=2;   
    }

    std::vector&lt;A&gt; *heapMembers; //ptr
};

int main()
{
    std::vector&lt;A&gt; aVec;  
    //I want to use updateHeap function in struct Heap to modify values of select elements of aVec


    A a0(2,5), a1(4,2), a2(8,4);  
        aVec.push_back(a0); aVec.push_back(a1); aVec.push_back(a2); 
        //Here I initialized aVec


    Heap minHeap1;
    //In minHeap1, I want to add elements one by one

    minHeap1.heapMembers-&gt;push_back(aVec[1]); 
    //I added a selected element (aVec[1]) in aVec to the heap; 
    minHeap1.updateHeap(minHeap.heapMembers-&gt;size()-1); 
    //I want to modify the value of aVec[1].a by calling updateHeap function
    std::cout &lt;&lt; aVec[1].a &lt;&lt; "\n";
    //Output: 4 , I want this value to be 2*4=8. 

    std::vector&lt;A&gt; heapVec;  
    heapVec.push_back(a1);

    Heap minHeap2(&amp;heapVec);
    //In minHeap2, I want to give it a vector of selected elements
    minHeap2.updateHeap(minHeap2.heapMembers-&gt;size()-1);
    //I want to modify the value of aVec[1].a by calling updateHeap function
    std::cout &lt;&lt;    aVec[1].a &lt;&lt; "\n";
    //Output: 4 , I want this value to be 2*4=8.
    std::cout &lt;&lt; heapVec[0].a &lt;&lt; "\n";
    //Output: 8 , This is the right answer, but I want aVec[1].a to take upon this value

    delete minHeap1.heapMembers;

    return 0;
}
</code></pre>
