title: Erase operation on vector not working
body: <p>I am new to C++ and I am having difficulties with getting the vector.erase operation to work.</p>
  
  <p>I have a database class as such:</p>
  
  <pre><code>template &lt;class T&gt; class Database
  {
      protected:
          std::vector&lt;T&gt; m_database;
          int m_counter;
      public:
          Database();
          virtual ~Database();
  
          // Accessor Methods.
          T&amp; getObject(int objectId);
          bool exists(int objectId);
  
          // Mutator Methods.
          void add(T Object);
          void del(int objectId);
  };
  </code></pre>
  
  <p>and in practice, I am using the code as such:</p>
  
  <pre><code>Database&lt;Account&gt; accountDatabase;
  </code></pre>
  
  <p><code>Account</code> is a base class, with two derived classes, <code>ChequingAccount</code> and <code>SavingsAccount</code>.</p>
  
  <p>I am inserting accounts, regardless of type (could be <code>Account</code>, <code>ChequingAccount</code>, <code>SavingsAccount</code>) into this database using:</p>
  
  <pre><code>template &lt;class T&gt; void Database&lt;T&gt;::add(T object)
  {
      m_database.push_back(object);
      ++m_counter;
  }
  </code></pre>
  
  <p>However, I am having issues with my delete operation. I am searching for a corresponding <code>objectId</code> and then deleting it from the vector.</p>
  
  <pre><code>// Deletes the specified object from the database.
  template &lt;class T&gt; void Database&lt;T&gt;::del(int objectId)
  {
      std::vector&lt;T&gt;&amp; database             = m_database;
      typename std::vector&lt;T&gt;::iterator it = database.begin();
  
      while (it != database.end()) {
          if ((*it).getId() == objectId) {
              it = database.erase(it);
          } else {
              ++it;
          }
      }
  }
  </code></pre>
  
  <p>Unfortunately the delete operation is not working at all. I am also having issues pulling a derived class from the database, as everything is being pulled out as an <code>Account</code> type. I believe these two issues are tied to my noob C++ skills and bad design.</p>
  
  <p>Any help would be greatly appreciated! Thanks!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>By not working, I mean the object is not deleted from the database. I apologize for any confusion.</p>
  
  <p>The Account classes:</p>
  
  <pre><code>class Account
  {
      protected:
          int m_id;
          double m_balance;
          std::string m_name, m_type;
      public:
          Account(int id, int userId, double balance = 0, std::string name = ""); // Constructor.
          ~Account(); // Destructor.
  
          // Accessor Methods.
          // This returns m_id AKA objectId
          int getId() const;
  }
  
  class ChequingAccount: public Account
  {
      public:
          ChequingAccount(int id, int userId, double balance, std::string name) : Account(id, userId, balance, name) {}
  }
  
  class SavingsAccount: public Account
  {
      public:
          SavingsAccount(int id, int userId, double balance, std::string name) : Account(id, userId, balance, name) {}
  }
  </code></pre>