4

For a raw pointer to an array in C++, the content of the first N elements can be seen by copying the expression into the Watch window of Visual Studio and appending a comma followed by the number of elements you want to see (for example: testArray, 10). How can the same memory content be seen in the Watch window when the array is created using a smart pointer? For example, if a unique_ptr is created via this statement:

unique_ptr<int[]> testArray = make_unique<int[]>(100)

How can we see the first 10 elements in the buffer?

2 Answers 2

4

The get() method of smart pointer should be used : testArray.get() , 10

Sign up to request clarification or add additional context in comments.

Comments

2

Try this watch: testArray._Mypair._Myval2, 10

2 Comments

This is reliant on implementation details. It's kind of a textbook example of what not to do, sorry ;)
@AsteroidsWithWings, true, but this works whereas x.get(),10 does not. test.get(),10 Function std::unique_ptr<__int64 [0],std::default_delete<__int64 [0]> >::get has no address, possibly due to compiler optimizations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.