c++ - 无法从 'std::vector<_Ty>' 转换为 'std::vector<_Ty> &

标签 c++

你好,我有两个问题:

  1. cannot convert from 'std::vector<_Ty>' to 'std::vector<_Ty> &

    void CMapObjectPropertyPageAmbience::OnUpdateUI(CProperty* pProperty)
    {
        prt::PropertyAmbienceStringToData(pProperty, &m_propertyAmbience);
    
        std::vector<CFilename>& rSoundFileNameVector = m_propertyAmbience.AmbienceSoundVector;
        for (DWORD dwIndex = 0; dwIndex < rSoundFileNameVector.size(); ++dwIndex)
        {
            m_ctrlSoundFileList.InsertString(dwIndex, rSoundFileNameVector[dwIndex].c_str());
        }
    
        m_ctrlPlayType.SelectString(-1, m_propertyAmbience.strPlayType.c_str());
    
        SetDialogFloatText(GetSafeHwnd(), IDC_MAP_OBJECT_PROPERTY_AMBIENCE_INTERVAL, m_propertyAmbience.fPlayInterval);
        SetDialogFloatText(GetSafeHwnd(), IDC_MAP_OBJECT_PROPERTY_AMBIENCE_INTERVAL_VARIATION, m_propertyAmbience.fPlayIntervalVariation);
        SetDialogFloatText(GetSafeHwnd(), IDC_MAP_OBJECT_PROPERTY_AMBIENCE_MAX_VOLUME_AREA_PERCENTAGE, m_propertyAmbience.fMaxVolumeAreaPercentage * 100.0f);
    
        OnUpdatePropertyData(m_propertyAmbience.strName.c_str());
        OnChangePlayType();
    }
    

    错误出现在:

    std::vector<CFilename>& rSoundFileNameVector = m_propertyAmbience.AmbienceSoundVector;
    
  2. 两个重载都不能转换所有参数类型:

    void CMapObjectPropertyPageAmbience::OnDeleteSoundFile()
    {
        DWORD dwCurSel = DWORD(m_ctrlSoundFileList.GetCurSel());
        if (dwCurSel >= m_propertyAmbience.AmbienceSoundVector.size())
            return;
    
        DeleteVectorItem < CFilename > ( & m_propertyAmbience.AmbienceSoundVector, dwCurSel);
        m_ctrlSoundFileList.DeleteString(dwCurSel);
    }
    

    DeleteVectorItem<CFilename>(&m_propertyAmbience.AmbienceSoundVector, dwCurSel);

全部错误

1>Dialog\MapObjectPropertyPageAmbience.cpp(78): error C2440: 'initializing' : cannot convert from 'std::vector<_Ty>' to 'std::vector<_Ty> &'
1>          with
1>          [
1>              _Ty=std::string
1>          ]
1>          and
1>          [
1>              _Ty=CFilename
1>          ]
1>Dialog\MapObjectPropertyPageAmbience.cpp(205): error C2665: 'DeleteVectorItem' : none of the 2 overloads could convert all the argument types
1>          d:\dev\kraizy\novaline\srcs\client\eterpack\../eterBase/Stl.h(146): could be 'void DeleteVectorItem<CFilename>(std::vector<_Ty> *,unsigned long)'
1>          with
1>          [
1>              _Ty=CFilename
1>          ]
1>          d:\dev\kraizy\novaline\srcs\client\eterpack\../eterBase/Stl.h(191): or       'void DeleteVectorItem<CFilename>(std::vector<_Ty> *,T)'
1>          with
1>          [
1>              _Ty=CFilename,
1>              T=CFilename
1>          ]
1>          while trying to match the argument list '(std::vector<_Ty> *, DWORD)'
1>          with
1>          [
1>              _Ty=std::string
1>          ]

最佳答案

您正在尝试使用 vector<string>vector<CFilename>的地方是期待。这些是完全不相关的类型。

关于c++ - 无法从 'std::vector<_Ty>' 转换为 'std::vector<_Ty> &,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20927514/

相关文章:

c++ - 元编程,阶乘,C++,boost

c++ - CFileDialog 的当前目录在.exe 和.dll 中不一致

c++ - 从基类继承函数声明中参数的默认值

c++ - 在 C++ 中,结构也是一个类吗?

c++ - 为 float 据类型赋值会导致程序崩溃

c++ - 为什么在 Visual Studio 中某些头文件需要链接库?

c++ - 为什么此线程池死锁或运行太多次?

C++ 嵌套条件运算符的求值顺序

c++ - 编译器如何定义 type_traits 中的类?

c++ - 调用了虚函数,使用了父函数