Elegant way to add a value to a member variable inside a vector I need to add an offset to a time variable inside my class.
The code below works, how do i make it more efficient, and elegant. 

#include &lt;array&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

class Pressure
{
    public:

    Pressure(int date, int time):m_date(date),m_time(time)
    {

    }

    int GetDate()
    {
        return m_date;
    }

    int GetTime()
    {
        return m_time;
    }

    void AddTime(int val)
    {
        m_time += val;
    }

    private:
    int m_date;
    int m_time;

};

int main()
{  
  std::vector&lt;Pressure&gt; p;

  // populate the vector with values.
  for(int i=0; i &lt; 10; i++)
  {
    Pressure x(i,i);
    p.push_back(x);
  }

  int offset = 20000;

  // add the offset 
  for(int i=0; i &lt; 10; i++)
  {
      p[i].AddTime(offset);
  }

  // display the data
  for(int i=0; i &lt; 10; i++)
  {
    std::cout &lt;&lt; p[i].GetDate() &lt;&lt; " "  &lt;&lt; p[i].GetTime() &lt;&lt; "\n";
  }

}
You could use a range-based for loop and push_back( Pressure(i,i) ).

#include &lt;iostream&gt;
#include &lt;vector&gt;

class Pressure {
public:
    Pressure(int date, int time) : m_date(date), m_time(time) {

    }

    int GetDate() const {
        return m_date;
    }

    int GetTime() const {
        return m_time;
    }

    void AddTime(int val) {
        m_time += val;
    }
private:
    int m_date;
    int m_time;
};

int main() {
    std::vector&lt;Pressure&gt; p;

    // populate the vector with values.
    p.reserve(10); // you can reserve space if you know the size ahead of time to prevent extra reallocations, but it isnt necessary for a vector this small.
    for(int i = 0; i &lt; 10; ++i) {
        p.push_back( Pressure(i,i) );
    }

    for(Pressure&amp; pressure : p) {
        // add offset
        pressure.AddTime(20000);

        // display data
        std::cout &lt;&lt; pressure.GetDate() &lt;&lt; " " &lt;&lt; pressure.GetTime() &lt;&lt; "\n";
    }

    return 0;
}