未定义的引用`静态类成员变量内部静态成员函数' [英] undefined reference to `Static Class Member variable inside Static member function'

查看:572
本文介绍了未定义的引用`静态类成员变量内部静态成员函数'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上试图实现Paging的模拟,在我的内存管理器,我尝试创建一个静态页表,但它给我的参考错误,当我尝试打印它。

  #ifndef MEMORYMANAGER_H 
#define MEMORYMANAGER_H
#includememory.h

class MemoryManager
{
private:
PhysicalMemory RAM;
LogicalMemory VM;
int offsetValue;
static int ** pageTable;
public:
MemoryManager();
bool addProcess(TimeSliceRequest);
void printVirtualMemory();
/ *
*页表初始化
** /
static void initializePageTable(){
pageTable = new int * [pageSize];
for(int i = 0; i pageTable [i] = new int [2];
}
}
static int getPageTabe(int x,int y){
return MemoryManager :: pageTable [x] [y] //未定义引用`MemoryManager :: pageTable'
}
static void printPageTable(){
for(int i = 0; i for int j = 0; j <2; j ++){
cout< getPageTabe(i,j);
}
cout<< endl;
}
}
};


#endif // MEMORYMANAGER_H

很长一段时间,请帮助

$ 成员变量,您还必须定义。这通过基本上在一个实现(源)文件中重复声明来实现:

  int ** MemoryManager :: pageTable; 


I am actually trying to implement a simulation of Paging, in my memory manager, i tried create a static page table, but its giving reference error when i try to print it.

#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

Getting this Error from a long long time, please help

解决方案

You only declare the pageTable member variable, you have to define it as well. This is done by basically repeating the declaration in an implementation (source) file:

int ** MemoryManager::pageTable;

这篇关于未定义的引用`静态类成员变量内部静态成员函数'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆