How does overloading operator[]  work?
<pre><code>struct rowDisplayPolicy
{
  static std::string seperator() { return ", "; }
};  

struct columnDisplayPolicy
{
  static std::string seperator() { return "\n  "; }
};

template &lt;typename T, int Size, typename DisplayPolicy&gt;
class Array {
public:
  Array() : pArray(new T[Size]) {}
  Array(T* pT) : pArray(new T[Size])
{
    for(int i=0; i&lt;Size; ++i)
    *(pArray + i) = *(pT + i);
}
  ~Array() { delete [] pArray; }
  T&amp; operator[](int n)
  {
    if(n&lt;0 || Size&lt;=n) throw std::Exception("index out of range");
    return *(pArray+n);
  }
  T operator[](int n) const
  {
    if(n&lt;0 || Size&lt;=n) throw std::Exception("index out of range");
    return *(pArray+n);
  }
  void display() const
  {
    std::cout &lt;&lt; "\n  ";
    for(int i=0; i&lt;Size-1; ++i)
      std::cout &lt;&lt; *(pArray+i) &lt;&lt; DisplayPolicy::seperator();
    std::cout &lt;&lt; *(pArray+Size-1) &lt;&lt; "\n";
  }
private:
  Array(const Array&lt;T,Size,DisplayPolicy&gt;&amp;);  // make public impl. Later
  Array&lt;T,Size,DisplayPolicy&gt;&amp; operator=(const Array&lt;T,Size,DisplayPolicy&gt;&amp;); // ditto
  T* pArray;
};
</code></pre>

<p>I have a question that, Why operator[]  overloading two different ways. and What's difference between them. I don't know clear the meaning of 'function() const'. can you show me some examples.</p>
