Vector 'no operator “[]” matches these operands' error in Visual Studio watch

筅森魡賤 提交于 2019-12-03 05:42:38

I found one solution which does not depend on the internals of the class. The expanded form of the operator call seems to work for me. In this case it's the following code:

v.operator[](0)

I tested it in Visual C++ 2012.

As @NateKohl noted, in Visual Studio 2012 (and possibly earlier versions as well) v._Myfirst gives a pointer to the underlying vector data, allowing you to watch the vector as if it were an array.

Visual Studio doesn't support stl containers' operator[] overloading, you simply have to manually set a watch on the element that you're interested in by selecting it from the list while debugging.

EDIT: if you want to inspect a T object inside a vector, assign it to a T object and set a watch on it instead

if you use 2D vecotr< vector< string > > dp, and you want to get dp[i][j] in watch window in VS2013, you can use (dp.operator [ ] (i)).operator [ ] (j)

vector< vector < string > > dp(n, vector < string >(n, ""));

(dp.operator [ ] (i)).operator [ ] (j)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!