0

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);
}
3
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

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);
}
0

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.

0

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.'

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.