7

I'm working in Vs2010 c++ with 2D arrays. I started off with a 1D pointer and used the operation [] as the following:

class CMatrix
{
    void clear();
public:
    int nRows;
    int nCols;
    short * MyMat;

    CMatrix();
    CMatrix(int r,int c);
    ~CMatrix(void);

    void SetMatrix(int r,int c);
    short * operator[] (const int row)
    {
        return MyMat + (row*nCols);
    }
};

I don't mind to change to 2D pointer.

However my problem is with debug. Because I'm using pointers I can't see the arrays content.

Are there any another options ?

I prefer not to use vector.

2

2 Answers 2

16

One way is to use use the Memory viewer. While debugging ( when stoped at a Breakpoint ), goto the menu Debug > Windows > Memory > Memory 1 to get the memory viewer. Then type-in the memory address ( copy paste the value from your pointer ) so that you can view the memory around that area of your program memory.

When you right click on memory viewer you can choose how you want to view the data ( as ANSI , as 4 integers, as 2 byte integers , as floats , bla bla... )

Also you can use the Watch window at the debug time. just use your pointer as an array ( e.g. if your pointer is char * t, the syntax t[0] will give your data pointed by the pointer t

8

In the QuickWatch window, you can type the name of the pointer variable followed by a comma and the number of array indices you want to view, e.g. MyMat, 10.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.