Reputation: 357
I'm writing this copy constructor:
//CCtor of RegMatrix
RegMatrix::RegMatrix(const RegMatrix &other){
this-> numRow = other.getRow();
this-> numCol = other.getCol();
//Create
_matrix = createMatrix(other.numRow,other.numCol);
int i,j;
//Copy Matrix
for(i=0;i<numRow; ++i){
for(j=0;j<numCol; ++j){
_matrix[i][j] = other._matrix[i][j];
}
}
}
Is there a problem to initialize numRow, numCol in the initialization list like this: numRow(other.numRow), numCol(other.numCol)
instead of:
this-> numRow = other.getRow();
this-> numCol = other.getCol();
Also, i don't know if there isn't such a problem, is there a problem of calling other classes' object's function in the initialization list, such as:
numRow(other.getRow())
instead of:
this-> numRow = other.getRow();
Upvotes: 7
Views: 6744
Reputation: 224049
Is there a problem to initialize numRow, numCol in the initialization list [...]?
In general, there's two problems with doing so:
In your concrete example this doesn't matter, so you are safe to do this.
Upvotes: 11
Reputation: 132994
No there is no problem actually. Except that be careful that the order of initialization is NOT the order in which you specify initializers in the init-list. The order is the one in which your members have been declared in the class. Other than that potential problem, I see none. HTH
Upvotes: 2