Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

view elements of class vector in the debug watch window

Status
Not open for further replies.

polocar

Programmer
Sep 20, 2004
89
IT
Hello,
I'm preparing a Visual C++ 6.0 project.
I use a vector<int> variable (called vec_num), and I noticed that, when I execute the program in debug mode and the execution stops to a breakpoint (after vector initialization), if I try to view the value of an element of the vector (writing for example vec_num[2] in the "Debug Watch Window"), an error is indicated in the value column (CXX0058: Error: overloaded operator not found), as if the subscript operator of the vector couldn't be identified.
The strange thing is that, writing the line
cout << vec_num[2] << endl;
after the breakpoint, the element is printed to monitor without problems.
How is it possible? Is there any way to view the values of vector elements during the execution of a program in debug mode?

Thank you very much
Carlo
 
It seems it's error in Watch mechanics (Quick Watch can't work too). Some (dirty) workaround: *(v._First+i) works...
 
Hi ArkM,
I tried to use your suggestion, and I noticed that _First is a protected member of vector, so it can be used only in vector-derivated-classes-code; but this idea suggested me that begin() is an equivalent public method, so
*(v_num.begin()+i) functions...
You are right, it's rather dirty, but at this point I think it's the only way.
Thank you for your help
 
Hi Polocar,
in debug windows you can see any members, not only public (it's not a common program/language context). Of course, your suggestion (with begin() member) is better than my brute force _First...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top