P
Peter Steele
Say I have a managed C++ app with some code that looks something like this:
void MyMethod()
{
struct Point { int x, y; };
Point* p = new Point;
p.x = 1;
p.y = 2;
....
}
During a debugging session, if I create a watch for the variable p, the
watch window does not display its contents. It says it is an invalid
pointer; Further more, if I create a watch for p->x or p->y, it says the
variable does not exist. If I change my code as follows:
struct Point { int x, y; };
....
void MyMethod()
{
Point* p = new Point;
p.x = 1;
p.y = 2;
....
}
then the Watch window correctly displays the value of p as a expandable
structure with a + sign that lets you see x and y as individual variables.
I also had something as simple as this:
{
int* pi = new int;
...
}
and the watch window displayed this value as invalid.
What's going on here anyway? I've experienced a lot of different cases where
the watch window just won't display the values of pointers and simple
structs, whereas in other cases it has no problems. Any suggestions would be
appreciated.
void MyMethod()
{
struct Point { int x, y; };
Point* p = new Point;
p.x = 1;
p.y = 2;
....
}
During a debugging session, if I create a watch for the variable p, the
watch window does not display its contents. It says it is an invalid
pointer; Further more, if I create a watch for p->x or p->y, it says the
variable does not exist. If I change my code as follows:
struct Point { int x, y; };
....
void MyMethod()
{
Point* p = new Point;
p.x = 1;
p.y = 2;
....
}
then the Watch window correctly displays the value of p as a expandable
structure with a + sign that lets you see x and y as individual variables.
I also had something as simple as this:
{
int* pi = new int;
...
}
and the watch window displayed this value as invalid.
What's going on here anyway? I've experienced a lot of different cases where
the watch window just won't display the values of pointers and simple
structs, whereas in other cases it has no problems. Any suggestions would be
appreciated.