• vs 在watch监视窗口 vector 错误 :overloaded operator not found


     一下的代码,debug显示是正常的。如果你调试时,查看watch窗口会发现一个错误:

    overloaded operator not found找不到重载运算符

    #include<iostream>
    #include<vector>
    #include<string>
    using namespace std;
    
    int main()
    {
        vector<vector<string> > vec;
        vector<string> vec1,vec2;
        vec1.push_back("can");
        vec1.push_back("you");
        vec2.push_back("speak");
        vec2.push_back("english");
        vec.push_back(vec1);
        vec.push_back(vec2);
    
        cout<<vec[0][0]<<endl;
    }

    原因:

    Codeview 的表达式计算器要求精确的参数匹配来评估重载的函数。此外的参数匹配,最高级别修饰符 (即,const,易失性) 将被忽略。

    The errors you have are due to limitations in the debugger, there are not bugs as Daniel implies.

    The watch window cannot call overloaded operators. If you have e.g. a std::vector<int> vecSomethingyou cannot put vecSomething[0] into the watch window, because std::vector<int>::operator[] is an overloaded operator. Consequently, for a vector of objects, you cannot dovecObject[0].SomeMemberVariableOfObject in the watch window. You could writevecObject._Myfirst[0].SomeMemberVariableOfObject. In Visual Studio's STL implementation,_Myfirst is a member of vector pointing at the first element.

    If you add your own variables and types to the watch window, add watches to the data members directly. It is no problem to follow chains of pointers like member.memberStruct.ptrToObj->memberOfObj.

    总之,加上_Myfirst即可。

    vec._Myfirst[0]._Myfirst[0]

    vec._Myfirst[1]._Myfirst[1]

    参考了:

    http://support.microsoft.com/kb/116370

    http://stackoverflow.com/questions/2179724/why-cant-i-index-a-stdvector-in-the-immediate-window

  • 相关阅读:
    3月16日
    11月8日
    Code4 APP
    为什么alertView弹出后button会消失的问题
    设置某个类使用或者禁用ARC
    Bundle使用&NSBundle
    respondsToSelector
    NSDate获取当前时区的时间
    iOS enum 定义与使用
    IOS开发之纯代码界面--基本控件使用篇 ┊
  • 原文地址:https://www.cnblogs.com/youxin/p/2550572.html
Copyright © 2020-2023  润新知