c++ - 结构数组的未定义 C++ 变量

标签 c++ variables

我在名为 index.cpp 的文件中有以下方法。当我编译时,它告诉我“indexStructure”未在此范围内定义。

#include "index.h"
#include <cctype> // provides isalpha() and tolower()
#include <iostream>
#include <sstream>

using namespace std;

void index::shiftRight (int i)
{
if ( indexSize == (sizeof(indexStructure) / sizeof(indexStructre[0])))
    doubleIndex();

for (int j = indexSize; j > i; j--)
    indexStructure [j] = indexStructure [j-1];
}

在 index.h 中,我有

class index
{

struct node {
    string item;
    int counter;
    int* pageNumber;
};

...

private:
    node* indexStructure;
    int lineCounter;
    int indexSize;

};

我打算制作一个节点类型的数组,并用它来搜索书中的单词。为什么它是未定义的?

提前致谢

最佳答案

您在 index::shiftRight() 中拼错了 sizeof(indexStructre[0])。将其更正为 indexStructure 并重试。

关于c++ - 结构数组的未定义 C++ 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12610681/

相关文章:

c++ - 为什么在重定向 stdout 和 stdin 时 Python 的行为不符合预期?

php - 为 mysql 创建一个 php 变量

C# System.Diagnostics.ProcessStartInfo EnvironmentVariables 不区分大小写?

c++ - 为什么我不能使用 if 和 if else 语句为变量赋值?

java - 通过 body 内的 taglib 定义变量

C++ 动态数组 - 通过复制两个数组

c++ - header : no such file or directory

c++ - 求 vector 的平均值

c++ - 成员函数指针指向另一个对象的方法

java - 如何从动态创建的 JTable 中获取值