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.
Tomas Restrepo \(MVP\) - 09 Oct 2004 04:01 GMT
Peter,
> Say I have a managed C++ app with some code that looks something like this:
>
[quoted text clipped - 41 lines]
> structs, whereas in other cases it has no problems. Any suggestions would be
> appreciated.
I commented on this a while back on my weblog [1]. Perhaps it might help you
understand a bit what's going on...
[1] http://www.winterdom.com/weblog/archives/000067.html

Signature
Tomas Restrepo
tomasr@mvps.org
Peter Steele - 11 Oct 2004 16:38 GMT
Thanks very much for this info. I suspected it had something to do with
managed/unmanaged code. The pointers in this weblog on the problem will
definitely help.
Peter
> Peter,
>
[quoted text clipped - 53 lines]
>
> [1] http://www.winterdom.com/weblog/archives/000067.html