Hi,
I have a class linestorage which has a static member S (represents lines of words of characters).
The problem is I don't know how to access this member in a function. I am getting this error message

Info :Linking C:\DOCUMENTS AND SETTINGS\DELL.DFHWHLB1\MY DOCUMENTS\SPRING 09\CSCI 250\HW\HW1\HW1_P2\kwic.exe
Error: Error: Unresolved external 'LineStorage::S' referenced from C:\DOCUMENTS AND SETTINGS\DELL.DFHWHLB1\MY DOCUMENTS\SPRING 09\CSCI 250\HW\HW1\HW1_P2\LINESTORAGE.OBJ

could you please help me to solve it.

//---------------- linestorage.h ----------------
#ifndef linestorage_H_
#define linestorage_H_
#include <vector.h>
using namespace std;

class LineStorage
{

   private:
        static vector <vector <vector<char> > > S;
   public:
   	void setchar(int,int,int,char);      
};
#endif

//---------------- linestorage.cpp ----------------

#include <iostream.h>
#include <conio.h>
#include "LineStorage.h"

void LineStorage::setchar(int l,int w,int c,char d)
{
    vector <char>::iterator it=LineStorage:: S[l][w].begin();
    LineStorage:: S[l][w].insert((it+c-1),d);
}

static class members have to also be declared globally just like any other global object

// in the *.cpp file
#include <iostream.h>
#include <conio.h>
#include "LineStorage.h"

LineStorage::vector <vector <vector<char> > > S;

void LineStorage::setchar(int l,int w,int c,char d)
{
    vector <char>::iterator it=LineStorage:: S[l][w].begin();
    LineStorage:: S[l][w].insert((it+c-1),d);
}

That is a linker error

You are right about that

- you'd have to setup your project to compile linestorage.cpp.

Nope -- nothing to do with that. See my previous post.

If I define vector <vector <vector<char> > > S; as a gloable variable it will work. However, I am not supposed to use gloable varialbes in this project.'

It is global but only within the scope of the class. If you want to make it static then you have no other choice than to declare it globally as I showed you.

This article has been dead for over six months. Start a new discussion instead.