除了三个补充成员函数外,我创建了一个可以正常工作的类。在所有其他公共(public)成员函数中,我指的是私有(private)数据成员,并且我可以轻松访问我需要的数据;但是,对于这三个特定函数,Dev C++ 编译器会响应:“'matrix' undeclared, first use this function (matrix is the private data member.)问题 child 。
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;
}
最佳答案
将 "boolMatrix::"添加到 totalCount() 和 colCount(int col)
关于c++ - 编译错误 : Undeclared member that is actually declared,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16579985/