Usm*_*hir 11 c++ static static-methods static-members
我实际上是在尝试实现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
Run Code Online (Sandbox Code Playgroud)
长时间获取此错误,请帮忙
Som*_*ude 22
你只声明的pageTable成员变量,你必须定义它.这是通过在实现(源)文件中基本重复声明来完成的:
int ** MemoryManager::pageTable;
Run Code Online (Sandbox Code Playgroud)