Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to `Static Class Member variable inside Static member function'

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

like image 348
Usman Tahir Avatar asked Jan 06 '13 20:01

Usman Tahir


1 Answers

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;
like image 147
Some programmer dude Avatar answered Oct 09 '22 17:10

Some programmer dude