2013-01-06 89 views
11

我實際上是試圖在我的內存管理器中實現Paging的模擬,我嘗試創建一個靜態頁表,但它給我參考錯誤,當我嘗試打印它。未定義的引用靜態成員函數裏面的靜態類成員變量

#ifndef MEMORYMANAGER_H 
#define MEMORYMANAGER_H 
#include "memory.h" 

class MemoryManager 
{ 
    private: 
     PhysicalMemory RAM; 
     LogicalMemory VM; 
     int offsetValue; 
     static int ** pageTable; 
    public: 
     MemoryManager(); 
     bool addProcess(TimeSliceRequest); 
     void printVirtualMemory(); 
     /* 
     * Page Table Initialization 
     **/ 
     static void initializePageTable(){ 
      pageTable = new int * [pageSize]; 
      for (int i=0; i<pageSize; i++) { 
       pageTable[i] = new int [2]; 
      } 
     } 
     static int getPageTabe(int x, int y) { 
      return MemoryManager::pageTable[x][y]; // undefined reference to `MemoryManager::pageTable' 
     } 
     static void printPageTable(){ 
      for(int i=0; i<pageSize; i++){ 
       for(int j=0; j<2; j++) { 
        cout << getPageTabe(i,j); 
       } 
       cout << endl; 
      } 
     } 
}; 


#endif // MEMORYMANAGER_H 

充分利用了很久很久這個錯誤,請幫助

回答

22

你只聲明pageTable成員變量,你必須定義它。這是通過基本上重複執行(源)文件中的聲明來完成的:

int ** MemoryManager::pageTable; 
+2

明白了:) 問題解決 –