Visual Studio无法显示某些监视的表达式 [英] Visual Studio fails to display some watched expressions
问题描述
在Visual Studio中,由于各种原因,在调试会话期间无法解析我的大多数对象和变量.这意味着我无法检查或监视对象或其调用它们的功能,这使得调试代码极为困难,因为我的大多数表达式都无法正常工作.将表达式添加到监视窗口时遇到的一些典型错误包括:
In Visual Studio, most of my objects and variables cannot be resolved during a debugging session for various reasons. This means I cannot inspect or watch objects or their invoke their functions making it extremely difficult to debug my code because most of my expressions simply won't work. Some typical errors I get when adding an expression to the watch window include:
- CXX0019:错误:类型转换错误
- CXX0059:错误:左操作数是类而不是函数名
- CXX0058:错误:找不到重载的运算符
这些表达式通常涉及重载的运算符和/或模板类对象.
Most often these expressions involve overloaded operators and/or template class objects.
为什么会这样?您如何解决?
Why is this happening? how do you fix it?
推荐答案
您遇到的错误是由于调试器中的限制所致,没有Daniel所暗示的错误.
The errors you have are due to limitations in the debugger, there are not bugs as Daniel implies.
监视窗口无法调用重载的运算符.
如果您有std::vector<int> vecSomething
您不能将vecSomething[0]
放入监视窗口,因为std::vector<int>::operator[]
是重载运算符.因此,对于对象向量,无法在监视窗口中执行vecObject[0].SomeMemberVariableOfObject
.您可以编写vecObject._Myfirst[0].SomeMemberVariableOfObject
.在Visual Studio的STL实现中,_Myfirst
是指向第一个元素的向量的成员.
The watch window cannot call overloaded operators.
If you have e.g. a std::vector<int> vecSomething
you 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 do vecObject[0].SomeMemberVariableOfObject
in the watch window. You could write vecObject._Myfirst[0].SomeMemberVariableOfObject
. In Visual Studio's STL implementation, _Myfirst
is a member of vector pointing at the first element.
如果将自己的变量和类型添加到监视窗口,请直接将监视添加到数据成员.遵循member.memberStruct.ptrToObj->memberOfObj
这样的指针链是没有问题的.
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
.
实际上,Visual Studio可以在监视"窗口中调用代码: http://geekswithblogs.net/sdorman/archive/2009/02/14/visual-studio-2008-debugging-ndash-the-watch-window.aspx
Actually Visual Studio can call code in the Watch window: http://geekswithblogs.net/sdorman/archive/2009/02/14/visual-studio-2008-debugging-ndash-the-watch-window.aspx
因此,为什么不能使用重载运算符有点神秘.
Thus, it is slightly mysterious why overloaded operators cannot be used.
这篇关于Visual Studio无法显示某些监视的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!