Function template
-
I keep getting the following error upon linking: "error LNK2001: unresolved external symbol "public: class CString __thiscall CMyDoc::FKeyReset(int)" This happens when I try to instantiate a function template. The code snippets are below. Does any one spot an obvious problem in it? Thanks, Ralf. MyDoc.h: template CString FKeyReset(T RecSet); MyDoc.cpp template CString FKeyReset(T RecSet) { CString str; if(T > 0) str.Format("message 1"); else str.Format("message 2"); return str; } Elsewhere outside MyDoc: CMyDoc *pMyDoc = (CFisheriesDoc *) //pointer to MyDoc ((CFrameWnd*) AfxGetApp()->m_pMainWnd)->GetActiveDocument(); CString szAstr; int i = 2; szAstr = pMyDoc ->FKeyReset(i); //offending line ralf.riedel@usm.edu
-
I keep getting the following error upon linking: "error LNK2001: unresolved external symbol "public: class CString __thiscall CMyDoc::FKeyReset(int)" This happens when I try to instantiate a function template. The code snippets are below. Does any one spot an obvious problem in it? Thanks, Ralf. MyDoc.h: template CString FKeyReset(T RecSet); MyDoc.cpp template CString FKeyReset(T RecSet) { CString str; if(T > 0) str.Format("message 1"); else str.Format("message 2"); return str; } Elsewhere outside MyDoc: CMyDoc *pMyDoc = (CFisheriesDoc *) //pointer to MyDoc ((CFrameWnd*) AfxGetApp()->m_pMainWnd)->GetActiveDocument(); CString szAstr; int i = 2; szAstr = pMyDoc ->FKeyReset(i); //offending line ralf.riedel@usm.edu
Yes. You can not do that... This link should explain why: http://www.codeproject.com/cpp/templatesourceorg.asp?target=templates%7C%2Dasp[^] John