c++ - Vector size() 被 NetBeans 标记为错误 : Unable to resolve Identifier

标签 c++ vector netbeans

所以我在 NetBeans 中使用 C++ 中的一些多维 vector ,每当我尝试调用 .size() 方法时,NetBeans 将其标记为红色并显示“无法解析标识符大小。 ”。但是,它确实可以识别其他 vector 方法,例如 .push_back()。虽然代码编译得很好......

这是我的代码:

#include <vector>
using namespace std;

typedef vector<int> int1D;
typedef vector<int1D> int2D;

int2D populate (int2D arg1, int arg2);

int main () {
    //Do stuff...
}

int2D populate (int2D grid, int gridSize) {
    int2D my_2d_array;
    //Here I fill my_2d_array...
    for (int x = 0; x < gridSize; x++) {
        for (int y = 0; y < gridSize; y++) {
            int value = grid[x][y];
            if (value == 0) {
                //get all coordinaes of values with 0
                int1D coordinates;
                coordinates.push_back(x);
                coordinates.push_back(y);
                my_2d_array.push_back(coordinates);
            }
        }
    }
    for (int x = 0; x < my_2d_array.size(); x++) {
        //do something
    }
}

这是错误突出显示的屏幕截图:

enter image description here

最佳答案

我有完全相同的症状,即我定义了一个 vector ,并且 它给出了相同的错误消息“无法解析标识符大小”, 编译成功。

执行以下操作有帮助:

右击项目->“代码帮助”->“清理C/C++缓存并重启IDE”

注意:这与“RightClick on project”->“Code Assistance”->“Reparse Project”不同,后者在几个帖子中提到过,但对我没有帮助。

关于c++ - Vector size() 被 NetBeans 标记为错误 : Unable to resolve Identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52863280/

相关文章:

c++ - 如何为股票创建一个类?

c++ - 创建对象数组 C++

Java在netbeans中清除jFrame

php - 在 Debian 操作系统上使用 NetBeans 和 XDebug 调试 Symfony2 项目

maven - NetBeans IDE为什么看不到生成的源?

c++ - 我要求用户输入大小和数组,但是在打印 vector 时,它仅将 '0'显示为输出

c++ - 未解析的外部符号 LNK 2001

c++ - vector 迭代器不可取消引用。成对的优先队列。

c# - "Type is not expected, and no contract can be inferred: Leap.Vector"错误。使用 Protobuf-net 序列化器

c++ - 对 STL 拷贝的推力无法按预期工作