sending address of a variable declared on the stack?
<p>I have a doubt concerning declaring variables, their scope, and if their address could be sent to other functions even if they are declared on the stack? <br>
<pre><code>
class A{
    AA a;
    void f1(){
        B b;
        aa.f2(&amp;b);
    }
};</p>

<p>class AA{
    B* mb;
    f2(B* b){
      mb = b; 
      //...
    }
};</p>

<p></pre></code>
Afterwards, I use my <code>AA::mb</code> pointer in the code.
So things I would like to know are following. <br>When the program exits <code>A::f1()</code> function, <code>b</code> variable since declared as a local variable and placed on the stack, can't be used anymore afterwards. </p>

<ol>
<li>What happens with the validity of the AA::mb pointer? <br>
It contains the address of the local variable which could not be available anymore, so the pointer isn't valid anymore?</li>
<li>If <code>B</code> class is a <code>std::&lt;vector&gt;</code>, and <code>AA::mb</code> is not a pointer anymore to that vector, but a vector collection itself for example. I would like to avoid copying all of it's contents in <code>AA::f2()</code> to a member <code>AA::mb</code> in line <code>mb = b</code>. Which solution would you recommend since I can't assign a pointer to it, because it'll be destroyed when the program exits <code>AA::f2()</code></li>
</ol>
