title: vector.push_back() method call is not working in c++
body: <p>I am new to c++, i am trying to read first four words of each line written in a file and assign to it a object of my class viz Detected_Object. I want to store these objects into vector. When i try to push_back object of my class into segmentation fault(Core Dumped) error comes.</p>
  
  <p>Other methods of vector like size, max_size() and capacity() are working fine on vector but on push_back() it is giving error.</p>
  
  <p>I have tried following workarounds that i have found so far:
  1. Tried using vector of pointers to object instead object itself.
  2. Tried to initialize vector with new keyword and then use it.
  3. Resized vector to hold 10 elements.
  but none of the above worked, i am not getting any clue of what i am doing wrong. The code base is as follow:</p>
  
  <pre><code>vector&lt;Detected_Object*&gt; objects;
  ifstream fp;
  string filename="../data/area_info/"+to_string(i)+".jpg.info";
  fp.open(filename);
  
  int left,right,top,bottom;
  string line;
  //end tracking if list of detected object is null
  if(fp &amp;&amp; fp.peek() == EOF){
      return;
  }else{
      //read all detected objects from single frame   
      while (getline(fp, line)) {
          int counter=0;
          istringstream buf(line);
          istream_iterator&lt;std::string&gt; beg(buf), end;
  
          std::vector&lt;std::string&gt; tokens(beg, end); // done!
          for(string&amp; s: tokens){
              std::cout &lt;&lt; '"' &lt;&lt; s &lt;&lt; '"' &lt;&lt; '\n';
              if(counter==0){
                  left=stoi(s);
              }else if(counter == 1){
                  right =stoi(s);
              }else if(counter == 2){
                  top = stoi(s);
              }else if(counter == 3){
                  bottom = stoi(s);      
                  counter=0;
                  cout&lt;&lt;"value of left coordinate: "&lt;&lt;left&lt;&lt;" right: "&lt;&lt;right&lt;&lt;" top: "
                  &lt;&lt;top&lt;&lt;" bottom: "&lt;&lt;bottom&lt;&lt;endl;
                  break;                                         
              }
              counter++;
          }
  
          Detected_Object obj(left,right,top,bottom);
          cout&lt;&lt;"max sizeof  vector of detected objects ";
          cout&lt;&lt;objects.max_size();
          //cout&lt;&lt;"detected object left: "&lt;&lt;obj.left&lt;&lt;"right: "&lt;&lt;right&lt;&lt;"top: "&lt;&lt;obj.top&lt;&lt;"bottom: "&lt;&lt;obj.bottom;
          objects.push_back(&amp;obj);
      }
  
  }
  </code></pre>
  
  <p>Edit:</p>
  
  <p>The following code also does not work:</p>
  
  <pre><code>vector&lt;Detected_Object&gt; objects = vector&lt;Detected_Object&gt;();
  Detected_Object obj;
  ifstream fp;
  string filename="../data/area_info/"+to_string(i)+".jpg.info";
  fp.open(filename);
  
  int left,right,top,bottom;
  string line;
  //end tracking if list of detected object is null
  if(fp &amp;&amp; fp.peek() == EOF){
      return;
  }else{
      //read all detected objects from single frame       
  
      while (getline(fp, line)) {
          int counter=0;
          istringstream buf(line);
          istream_iterator&lt;std::string&gt; beg(buf), end;
  
          std::vector&lt;std::string&gt; tokens(beg, end); // done!
          for(string&amp; s: tokens){
              std::cout &lt;&lt; '"' &lt;&lt; s &lt;&lt; '"' &lt;&lt; '\n';
              if(counter==0){
                  left=stoi(s);
              }else if(counter == 1){
                  right =stoi(s);
              }else if(counter == 2){
                  top = stoi(s);
              }else if(counter == 3){
                  bottom = stoi(s);      
                  counter=0;
                  cout&lt;&lt;"value of left coordinate: "&lt;&lt;left&lt;&lt;" right: "&lt;&lt;right&lt;&lt;" top: "
                  &lt;&lt;top&lt;&lt;" bottom: "&lt;&lt;bottom&lt;&lt;endl;
                  break;                                         
              }
              counter++;
          }
  
          obj = Detected_Object(left,right,top,bottom);
          objects.push_back(obj);
      }
  
  }
  </code></pre>
  
  <p>Please help me to find out the way to rid of this error.</p>
  
  <p>Thanks.</p>