title: Wrong operator() overload called
body: <p>I am writing a matrix class and have overloaded the function call operator twice. The core of the matrix is a 2D double array. I am using the MinGW GCC compiler called from a windows console.</p>
  
  <p>The first overload is meant to return a double from the array (for viewing an element).
  the second overload is meant to return a reference to a location in the array (for changing the data in that location.</p>
  
  <pre><code>double operator()(int row, int col) const ; //allows view of element
  
  double &amp;operator()(int row, int col); //allows assignment of element
  </code></pre>
  
  <p>I am writing a testing routine and have discovered that the "viewing" overload never gets called. for some reason the compiler "defaults" to calling the overload that returns a reference when the following printf() statement is used.</p>
  
  <pre><code>fprintf(outp, "%6.2f\t", testMatD(i,j));
  </code></pre>
  
  <p>I understand that I'm insulting the gods by writing my own matrix class without using vectors and testing with C I/O functions. I will be punished thoroughly in the afterlife, no need to do it here.</p>
  
  <p>Ultimately I'd like to know what is going on here and how to fix it. I'd prefer to use the cleaner looking operator overloads rather than member functions.</p>
  
  <p>Any ideas?</p>
  
  <p>The matrix class: irrelevant code omitted.</p>
  
  <pre><code>
      class Matrix
  
      {
      public:
   double  getElement(int row, int col)const; //returns the element at row,col
  
   //operator overloads
   double operator()(int row, int col) const ; //allows view of element
   double &operator()(int row, int col); //allows assignment of element
  
      private:
   //data members
   double  **array;   //pointer to data array
  
      };
  
      double Matrix::getElement(int row, int col)const{
    //transform indices into true coordinates (from sorted coordinates
    //only row needs to be transformed (user can only sort by row)
    row = sortedArray[row];
  
    result = array[usrZeroRow+row][usrZeroCol+col];
    return result;
      }
  
      //operator overloads
      double Matrix::operator()(int row, int col) const {
       //this overload is used when viewing an element
       return getElement(row,col);
      }
  
      double &Matrix::operator()(int row, int col){
       //this overload is used when placing an element
    return array[row+usrZeroRow][col+usrZeroCol];
      }
  </code></pre>
  
  <p>The testing program: irrelevant code omitted.</p>
  
  <pre><code>int main(void){
  
   FILE *outp;
  
   outp = fopen("test_output.txt", "w+");
  
      Matrix testMatD(5,7); //construct 5x7 matrix
  
      //some initializations omitted
      fprintf(outp, "%6.2f\t", testMatD(i,j));   //calls the wrong overload
  }
  </code></pre>