title: In c++,where does List<int>::push_back(int item) deploy the item to?To the stack or to the heap?
body: <p>I am writing a list class to hold a set of integers. It includes a member function &quot;push_back(int item)&quot; to push integers into the back of the list.</p>
  <h2>What I am intending to do:</h2>
  <p>When push_back(1) is executed, I want the computer do two things:
  First,initialize an myNode object (on the stack) with an int member valued as 1
  Next,push the myNode object to the back of the list</p>
  <h2>The problem I meet:</h2>
  <p>As the code shown below, when push_back() finished,the newNode object disappears because it was build on the stack.But I want it leaves on the stack upon the list object.</p>
  <h2>Why I build the object on the stack:</h2>
  <p>After doing some research I found that the &quot;new&quot; keyword should be avoided if not necessary, and so now I am trying to deploy things on stack.</p>
  <h2>So my question is:</h2>
  <ol>
  <li>How to do this in a safe, efficient and elegant way.</li>
  <li>There's a function list::push_back(int item) in the STL template. I would like to know how it deals with my problem.</li>
  </ol>
  <h2>Code:</h2>
  <pre><code>class myNode
  {
   myNode* next;
   myNode* before;
   myNode(int item){
   this-&gt;item=item;
  }
   int item;
  }
  class myList
  {
   myNode* headNode;
   myNode* lastNode;
  
   void push_back(int item)
   {
    //here,the newNode is on the stack and it would disappear after the function ends
    myNode* newNode=&amp;myNode(item);
  
   //doing other stuff
   lastNode-&gt;next = newNode;
   newNode-&gt;before = lastNode;
   newNode-&gt;next = headNode;
  
   //renew the lastNode
   lastNode=newNode;
  ...
   }
  
  }
  
  void main(){
  myList lst;
  lst.push_back(1);
  lst.push_back(2);
  ...
  }
  </code></pre>
  <h2>Complement:</h2>
  <p>As a noob, everything I'm assuming could be wrong, such as avoiding &quot;new&quot; keywords in the push_back(). So feel free if you think any part of it should be revised totally.
  C++ is mind-blowing, thanks for you all in advance, salute o7!</p>