static class members and LNK2001 error

J

Jiaxin Deng

Who can tell me why? I am trying to declare a static class memeber of a
CDialog object. The purpose is to store the input data in a static
Vector object and therefore make it independent of the dialog object.
The program compiles without problem, but VC6 compiler reports a link
error during the link stage. The code and error is quoted below.

class CDataInput : public CDialog
{
CDataInput(CWnd* pParent /*= NULL*/); CWnd* m_pParent;
static CityVector theVector;
...
}

void CDataInput::OnAdd()
{
UpdateData(TRUE);
//verify the validity of the data
if(m_CoordX==NULL || m_CoordY==NULL)
{
AfxMessageBox("please input data in the valid format");
return;
}

//store the coordinate data in an CMap object
CCity NewCity;
NewCity.m_Longitude = m_CoordX;
NewCity.m_Latitude = m_CoordY;
NewCity.CityID++;
NewCity.CityID = nCounter;
nCounter++;
// Append one element to the end of the vector
theVector.push_back(NewCity);
//output the coordinate data to the CTextView
...
}


Linking...
DataInput.obj : error LNK2001: unresolved external symbol "public:
static class std::vector<class CCity,class std::allocator<class CCity> >
CDataInput::theVector"
(?theVector@CDataInput@@2V?$vector@VCCity@@V?$allocator@VCCity@@@std@@@s
td@@A)
SplitWndDoc.obj : error LNK2001: unresolved external symbol "public:
static class std::vector<class CCity,class std::allocator<class CCity> >
CDataInput::theVector"
(?theVector@CDataInput@@2V?$vector@VCCity@@V?$allocator@VCCity@@@std@@@s
td@@A)
Debug/SplitWnd.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top