c++ - 编译错误 : Undeclared member that is actually declared

标签 c++ class compiler-errors datamember

除了三个补充成员函数外,我创建了一个可以正常工作的类。在所有其他公共(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/

相关文章:

c++ - SFML 渲染目标.draw : Invalid use of incomplete type

c++ - 在 C++ 中,使用终端窗口读取文件后如何使用标准输入?

c++ - 使用 WinAPI 附加禁用的显示设备

javascript - 当元素包含类时如何选中复选框?

ruby - 为什么当我运行 ruby​​ 脚本时,类内部的代码会自动执行?

asp.net-mvc - 访问asp.net mvc Controller ActionResult

c++ - 操作系统是否锁定计算机内的全部内存

java - 在 Java 中创建类数组(而不是对象)?

Android内核编译错误-从类型 ‘uid_t’分配给类型 ‘kuid_t’时类型不兼容

c++ - 'while' 之前的意外不合格 ID