我想寫一個程序,但我不明白爲什麼我的私人會員功能不能訪問我的私人數據成員。有人請幫忙嗎?這是我的功能。 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
請讓我知道如果我可以提供任何其他信息。
是:什麼是編譯器錯誤信息? (具體來說,它指的是哪一行代碼?) –