Q:

How do I implement matrix.Transpose() for my non-static Transpose function?

I have been given the following code in a test.cpp file to implement:
cout << "Case 2: the non-static Transpose function" << endl;
{
    double column[4] = {2, 1, 0, -1};
    double row[3] = {2, 0, -1};
    Matrix matrix = Matrix::Toeplitz(column, 4, row, 3);
    cout << "The original Matrix = " << endl;
    cout << matrix << endl;  //This part of the code works

    matrix.Transpose();  //How do I implement this?
    cout << "The transposed version = " << endl;
    cout << matrix << endl;
    cout << "Press any key to continue ..." << flush;
    system("read");
    cout << endl;
}

The way Matrix::Toeplitz(column, 4, row, 3) works is as follows:
Matrix Matrix::Toeplitz(const double* column, const int noOfRows, const double* row, const int noOfColumns){
    Matrix outT(column, noOfRows, row, noOfColumns);
    return outT;
}

So how would I implement matrix.Transpose()?  My code so far is as follows:
Matrix& Matrix::Transpose () {

double newrow[noOfRows];
for(int i=0; i<noOfRows; i++){
    int index = GetIndex(i,0);
    newrow[i] = data[index];
}

double newcol[noOfColumns];
for(int i=0; i<noOfColumns; i++){
    int index = GetIndex(0,i);
    newcol[i] = data[index];
}

Matrix outT(newcol, noOfColumns, newrow, noOfRows);
}

This has no effect on cout<<matrix<<endl;
I was thinking that Matrix outT(newcol, noOfColumns, newrow, noOfRows); should give new information (i.e. switching the column and row arrays) to the matrix object when implementing matrix.Transpose but it hasn't been working.
Is this the correct format Matrix& Matrix::Transpose () for implementing matrix.Transpose()?

A:

Matrix::Transpose can't return a reference to a locally declared object. This will lead to many problems. 
See C++ Returning reference to local variable.
It must return by copy (then, function can be const, as current object is not being modified):
Matrix Matrix::Transpose() const
{
    double newrow[noOfRows];
    for(int i=0; i<noOfRows; i++){
        int index = GetIndex(i,0);
        newrow[i] = data[index];
    }

    double newcol[noOfColumns];
    for(int i=0; i<noOfColumns; i++){
        int index = GetIndex(0,i);
        newcol[i] = data[index];
    }

    return Matrix(newcol, noOfColumns, newrow, noOfRows);
}

Then, you use it this way:
Matrix transposed = matrix.Transpose(); // does not modify matrix object
cout << "The transposed version = " << endl;
cout << transposed << endl;

If returning Matrix&, you need to have your method transpose the current object and return it (return *this), only useful to help caller to chain many operators (like doing m.Transpose().Transpose() for instance).
Then, it could be (not tested):
Matrix& Matrix::Transpose() 
{
    // backup old content
    double* backupData = new double[noOfRows*noOfColumns];
    memcpy( backupData, data, sizeof(double)*noOfRows*noOfColumns );

    // change matrix geometry
    int oldRowCount = noOfRows;
    noOfRows = noOfColumns;
    noOfColumns = oldRowCount ;

    // transpose matrix by copying from backup content
    for ( unsigned int line = 0; line < noOfRows ; ++line )
    {
        for ( unsigned int col = line; col < noOfColumns; ++col )
        {
            data[line * noOfColumns + col] = backupData[col * noOfRows  + line];
        }
    }

    delete [] backupData;

    return *this;
}

Then, you use it this way:
matrix.Transpose(); // modifies matrix object
cout << "The transposed version = " << endl;
cout << transposed << endl;

