Sign in to follow this  
Mad_Coder

Debugging Container Objects

Recommended Posts

Hello I have a simple containers such as vectors, vectors of vectors and maps that I want to be able to add to the watch\autos window when stepping into my code in MSVC++ 2003, but I do not get how I am supposed to observe elements and elements of elements ( for containers of containers ) of the containers? For an example, a simple vector<int> vecA; container object is added to the watch1 window, and shows these details once the object is initialized: - vecA {first=??? last=???} std::vector<int,std::allocator<int> > - std::_Vector_val<int,std::allocator<int> > {_Alval={...} } std::_Vector_val<int,std::allocator<int> > - _Alval {...} std::allocator<int> std::_Allocator_base<int> {...} std::_Allocator_base<int> - _Myfirst 0xcccccccc int * CXX0030: Error: expression cannot be evaluated int - _Mylast 0xcccccccc int * CXX0030: Error: expression cannot be evaluated int - _Myend 0xcccccccc int * CXX0030: Error: expression cannot be evaluated int *((vecA)._Myend) CXX0030: Error: expression cannot be evaluated int How do I get the vectors members to show up and is there a way to access the members of the different elements?

Share this post


Link to post
Share on other sites
That's not initialized. 0xCCCCCCCC is a common fill pattern indicating an uninitialized variable, as all of std::vector's members appear to be right now, which is why it's not showing you any of vector's members.

Relevant Clicky (you may want to start at the beginning of that great article)

I can't remember if VS2k3 did what VS2k5 and up do with showing std::vectors in a clean array-like manner, but I'd typically try to view the _Myfirst pointer as an array if not. But, first, you need to have std::vector in an initialized state, for either :).

Share this post


Link to post
Share on other sites
Thanks so much for that article, i will definently keep that in my favorites. How do can I use a subcript of the _MyFirst pointer to use it as an array? The way I am moving through the elements is copying the hexadecimal form of the what adress _Myfirst is poitning to by the number of bytes each element tpye takes up. For instance a vector<int> v; MyFirst is 0x00000005 ( which really whould be pointing to a null value most likely with suhc a close value to 0x000000000 but this is an example) I then add 4 to it so now the adress is 0x00000009 which is the second element. What way were you refering to using the _MYfirst pointer as an array and indexing it?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this