除了三个补充成员函数外,我创建了一个可以正常工作的类。在所有其他公共成员函数中,我指的是私有数据成员,并且我可以轻松访问我需要的数据;但是,对于这三个特定函数,Dev C++ 编译器会响应:“'matrix' undeclared, first use this function (matrix is the private data member.)问题儿童。
bool boolMatrix::get(int row, int col) const{
assert (row < ROW_SIZE && col < COL_SIZE);
if(matrix[row][col]){
return true;
}
else
return false;
}
int rowCount(int row){
int trueCount = 0;
assert(row < ROW_SIZE);
for (int colCount = 0; colCount < COL_SIZE; colCount++){
if(matrix[row][colCount]){
trueCount++;
}
}
return trueCount;
}
int colCount(int col){
int trueCount = 0;
assert(col < COL_SIZE);
for (int rowCount = 0; rowCount < ROW_SIZE; rowCount++){
if(matrix[rowCount][col]){
trueCount++;
}
}
return trueCount;
}
int totalCount(){
int trueCount = 0;
for (int rowCount = 0; rowCount < ROW_SIZE; rowCount++){
for (int colCount = 0; colCount < COL_SIZE; colCount++){
if (matrix[rowCount][colCount]){
trueCount++;
}
}
}
return trueCount;
}