2011-11-28 2 views
1

프로그램을 작성하려고하지만 개인 멤버 함수가 개인 데이터 멤버에 액세스 할 수없는 이유를 알 수 없습니다. 누군가 제발 도와 주겠습니까? 내 기능은 다음과 같습니다. nStock, capacity 및 slots []은 모두 개인 데이터 멤버이며 hashStr()은 private 함수입니다.개인 멤버 함수의 비 정적 멤버에 대한 잘못된 참조

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 

내가 추가 정보를 제공 할 수 있는지 알려 주시기 바랍니다 :

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 파일의 개인 회원 섹션입니다.

+1

예 : 컴파일러 오류 메시지가 무엇입니까? (구체적으로 어떤 코드 행이 참조됩니까?) –

답변

4

코드는 search라는 비 멤버 함수를 생성 ... 질문을 명확히해야합니다.

bool ClassName::search(char * symbol) 

클래스의 이름으로 ClassName 교체 :

bool search(char * symbol) 

에 : 당신은 변경해야합니다.

3

함수는 정적입니다. 그 이유는 무엇입니까? 정적 함수는 클래스의 정적 멤버에만 액세스 할 수 있습니다.

편집 : 다른 답도 정확 수은 실제로 당신이

관련 문제