我想写一个程序,但我不明白为什么我的私人会员功能不能访问我的私人数据成员。有人请帮忙吗?这是我的功能。 nStocks,capacity和slots []都是私有数据成员,而hashStr()是一个私有函数。私人会员功能中的非静态成员非法引用
bool search(char * symbol)
{
if (nStocks == 0)
return false;
int chain = 1;
bool found = false;
unsigned int index = hashStr(symbol) % capacity;
if (strcmp(symbol, slots[index].slotStock.symbol) != 0)
{
int start = index;
index ++;
index = index % capacity;
while (!found && start != index)
{
if(symbol == slots[index].slotStock.symbol)
{
found = true;
}
else
{
index = index % capacity;
index++;
chain++;
}
}
if (start == index)
return false;
}
return true;
}
这里是我的.h文件的私有成员部分:
private:
static unsigned int hashStr(char const * const symbol); // hashing function
bool search(char * symbol);
struct Slot
{
bool occupied;
Stock slotStock;
};
Slot *slots; // array of instances of slot
int capacity; // number of slots in array
int nStocks; // current number of stocks stored in hash table
请让我知道如果我可以提供任何其他信息。
是:什么是编译器错误信息? (具体来说,它指的是哪一行代码?) –