簡體   English   中英

錯誤C2664:無法將參數1從'const std :: basic_string <_Elem,_Traits,_Ax>'轉換為'std :: wstring&

[英]error C2664: cannot convert parameter 1 from 'const std::basic_string<_Elem,_Traits,_Ax>' to 'std::wstring &

error C2664: 'CCertStoreHelper::DeleteCtl' : cannot convert parameter 1 from 'const std::basic_string<_Elem,_Traits,_Ax>' to 'std::wstring &error C2664: 'CCertStoreHelper::DeleteCtl' : cannot convert parameter 1 from 'const std::basic_string<_Elem,_Traits,_Ax>' to 'std::wstring &
with
      [
              _Elem=wchar_t,
              _Traits=std::char_traits<wchar_t>,
              _Ax=std::allocator<wchar_t>
      ]
      Conversion loses qualifiers

我不知道這個。 所以請提供解決方案。

碼:

CCertStoreHelper certCaStore;
std::set<std::wstring> ctlIdentifiersToRemove; // It populates data which I m not mentioning


std::set<std::wstring>::iterator iter1;
std::set<std::wstring>::iterator iter2;

for(iter1 = ctlIdentifiersToRemove.begin(); iter1 != ctlIdentifiersToRemove.end(); iter1++)
{
    iter2 = ctlIdentifiersReferenced.find((*iter1));
    if(iter2 == ctlIdentifiersReferenced.end()) 
    {
        if(certCaStore.DeleteCtl((*iter1))) // error line
        {
            // ...
        }
    }
}
// prototype for DeleteCtl fun is
bool CCertStoreHelper::DeleteCtl(std::wstring &ctlIdentifier)

請糾正我的錯誤,謝謝

正如twalberg所指出的,編譯器錯誤消息中最重要的一點是“丟失限定符”位。 它還告訴你它不能從const std::wstring轉換為std::wstring& ,除了它將第一個std::wstring擴展為其完整的模板實例化形式。

問題是你的DeleteCtl通過非const引用獲取參數,好像它想在那里修改字符串(壞主意),但它不能這樣做,因為你在一個集合上迭代,你不能改變一旦他們在那里的一個集合的成員( std::setconst_iteratoriterator之間沒有區別,基本上)。 原因是std::set將其內部結構基於其元素的值,如果更改這些值,內部結構將變為無效,並且會發生可怕的事情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM