读书人

指针初始化为NULL没有进行任何操作

发布时间: 2013-10-21 17:02:52 作者: rapoo

指针初始化为NULL,没有进行任何操作,变成0xffffffffffffffff
typedef struct Test{
Node * node;
test(){
node = NULL;
}
}Test;
typedef struct Node{
Node1 * left;
Node(){
left = NULL;
}
}Node;
typedef struct Node1{
Node1 * next;
Node1(){
next = NULL;
}
}Node1;

int main(){
Test a = new test[2];
a[0].node.left = new Node[10000000];
a[1].node.left = new Node[10000000];
long int * b = new long int[100000000]
......

}

中间经过一些对a[0].node.left的插入一些Node1结点。没有问题。当对a[1].node.left进行插入Node结点的时候,发现a[1].node.left[0],a[1].node.left[1]......已经不为NULL(0),变成了0xffffffffffffffff,后边的a[1].node.left[n]......到最后还是NULL(0).
如果没有对b申请空间那一行,则没有错误,为什么会是这样?
[解决办法]
Setting a Breakpoint When a Variable Changes Value
To set a breakpoint when a variable changes value

From the Edit menu, click Breakpoints.


Click the Data tab of the Breakpoints dialog box.


In the Expression text box, type the name of the variable.


Click OK to set the breakpoint.

[解决办法]
一般指针不会0xffffffffffffffff这么大,调试看看是被什么越界的操作改写了。

引用:
typedef struct Test{
Node * node;
test(){
node = NULL;
}
}Test;
typedef struct Node{
Node1 * left;
Node(){
left = NULL;
}
}Node;
typedef struct Node1{
Node1 * next;
Node1(){
next = NULL;
}
}Node1;

int main(){
Test a = new test[2];
a[0].node.left = new Node[10000000];
a[1].node.left = new Node[10000000];
long int * b = new long int[100000000]
......

}

中间经过一些对a[0].node.left的插入一些Node1结点。没有问题。当对a[1].node.left进行插入Node结点的时候,发现a[1].node.left[0],a[1].node.left[1]......已经不为NULL(0),变成了0xffffffffffffffff,后边的a[1].node.left[n]......到最后还是NULL(0).
如果没有对b申请空间那一行,则没有错误,为什么会是这样?

读书人网 >C++

热点推荐