error LNK2001: unresolved external error

I got this error. could any guru help me ?
I just define a list of strings for the header of a list view.

1. in h file
static const std::string m_columnHeading[NUMBR_COLUMN];

2. in ccp file
initialize the strings
const std::string m_columnHeading[NUMBR_COLUMN] ={"s/m","num_1","eid","p_eid","dest","cdts","amount","recon ts"};

to use the strings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
BOOL CCSMessageRecon::OnInitDialog()
{
	CDialog::OnInitDialog();

	LVCOLUMN lvColumn;
	int nColmn;
	for(nColmn=0; nColmn<GetArrLength(m_columnWidth); nColmn++)
	{
		lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
		lvColumn.fmt = LVCFMT_LEFT;
		lvColumn.cx = m_columnWidth[nColmn];
		char   txt[50];
		strncpy(txt, m_columnHeading[nColmn].c_str(),m_columnHeading[nColmn].length()+1);
		lvColumn.pszText =txt;
		m_csmsg.InsertColumn(nColmn, &lvColumn);

	}
	return TRUE; // return TRUE unless you set the focus to a control

}


there is no problem in comilation. but got a link error. when I comment out the line, it will be fine.
strncpy(txt, m_columnHeading[nColmn].c_str(),m_columnHeading[nColmn].length()+1);
I think you need to declare the variable as extern in the header file. Basically, in files that are using the variable other than the cpp where you define it, you need to specify extern, sort of like a prototype for a function.
thanks Zhuge

but it doesn't work with extern. actually the m_columnHeading variable is a dialog class variable. the calling function and the varialbe are in the class context.
sorry. I found the problem. I forget adding the class name:
const std::string CCSMessageRecon:: m_columnHeading[NUMBR_COLUMN] ={"
That makes more sense then. I had assumed it was a global variable.
Topic archived. No new replies allowed.