title: C++ generic array implementation
body: <p>I came lately across a C++ recruitment test. They are asking the 4 following questions.</p>
  
  <ol>
  <li>There are at least 4 different bugs in the implementation of the
  following Array class. </li>
  <li>Provide for at least 2 of them a test case for each bug.</li>
  <li>Propose a ﬁx for each bug</li>
  <li>Assuming we have a bug-free implementation of Array class, do you think
  there are any design problems with it?</li>
  </ol>
  
  
  
  <pre><code>template &lt;class T&gt; class Array {
  private:
      T *m_pData;
      unsigned int m_nSize;
  
  public:
  
      Array(unsigned int nSize) : m_nSize( nSize)
      { 
          if ( m_nSize &gt; 0)
              m_pData = new ( nothrow) T[ m_nSize];
      } 
  
      virtual ~Array() 
      { 
          if(m_pData != NULL)
              delete m_pData; 
      } 
  
      bool Set(unsigned int nPos, const T&amp; Value) 
      {
          if(nPos &lt; m_nSize) {
              m_pData[nPos] = Value;
              return true;
          }
          else 
              return false;
      }
  
      T Get(unsigned int nPos) {
          if(nPos &lt; m_nSize) {
              return m_pData[nPos];
          }
          else 
              return T();
      }
  };
  </code></pre>
  
  <p>The problem is I can see no bug.
  Yes, there are some weird code like:</p>
  
  <ul>
  <li>checking before calling delete</li>
  <li>returning a default value in Get when outofbounds</li>
  <li>using delete instead of delete []</li>
  </ul>
  
  <p>But these are no bugs to me.</p>