سؤال

I just don't see where I went wrong. The compiler complains about

Error   215 error LNK2001: Unresolved external symbol ""class std::vector<class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >,class std::allocator<class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > > > __cdecl splitW(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > &,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (?splitW@@YA?AV?$vector@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@V?$allocator@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@2@@std@@AAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@2@ABV32@@Z)".   C:\voice\clsText.obj    voice

But I don't see where I went wrong. Can somebody tell me how to analyze this error message? I get it quite often, but then again I never remember how I solved it.

Thank you very much!

This is my code in strhelper.cpp:

vector<wstring> splitW(const wstring& uMain, const wstring &uSplitBy)
{
    vector<wstring>s;

    int iStart=0;

    for (;;)
    {
        int iPos=uMain.find(uSplitBy,iStart);
        if (iPos==-1)
        {
            wstring s1;
            s1 = uMain.substr(iStart,uMain.size() - iStart);
            if (s1.size()>0)
            {
                s.push_back(s1);
            }
            break;
        }
        else
        {
            wstring s2;
            s2 = uMain.substr(iStart,iPos-iStart);
            s.push_back(s2);
            iStart = iPos + 1;
        }
    }
    return s;
}

And this is the part of the header that contains the declaration:

void replaceOnce(wstring& uText,const wstring& uSearchFor,const wstring& uReplaceWith,bool uTextCompare);
vector<wstring> splitW(wstring &str, const wstring &uSep);
vector<wstring> splitAToWVec(const string& uMain, const string& uSplitBy);
vector<string> splitAToAVec(const string& uMain, const string& uSplitBy);
هل كانت مفيدة؟

المحلول

The type of the 1st parameter of splitW() is declared as wstring& in header file but defined as const wstring& in source code. Please make them consistent.

نصائح أخرى

Declaration:

vector<wstring> splitW(      wstring& str,  const wstring &uSep);

Definition:

vector<wstring> splitW(const wstring& uMain, const wstring &uSplitBy)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top