C ++编程错误 - 运行时错误

时间:2015-05-18 00:27:18

标签: c++

执行下面的c ++代码时出现运行时错误。有人可以帮我解释为什么我会收到这个运行时错误。

#include<iostream>
using namespace std;

struct node
{
   int data;
   struct node *left;
   struct node *right;
   struct node *rlink;
};

struct qnode
{
   struct node *lnode;
   int level;
};

struct node* newnode (int n)
{
   struct node *temp;
   temp= new struct node;
   temp->data=n;
   temp->left=NULL;
   temp->right=NULL;
   temp->rlink=NULL;
   return temp;
}

void link (struct node *n, int level)
{
  struct qnode *qn;
  struct qnode *current, *next;
  struct qnode nextd;
  next = &nextd;

  (next->lnode)->data=5;
  cout << (next->lnode)->data << endl;

}


int main()
{
    struct node *root = newnode(10);
    root->left        = newnode(8);
    root->right       = newnode(2);
    root->left->left  = newnode(3);


    link (root, 0);
    return 0;


  }

2 个答案:

答案 0 :(得分:2)

在你的链接功能中,你这样做了:

next = &nextd;

nextd未初始化,并且当其地址分配给next时包含垃圾值。然后下一行尝试访问它,这会导致访问冲突错误。

答案 1 :(得分:2)

问题在于链接:

document.getElementById("popupcontent").innerHTML += "<img class='popupbanner' src='" + eventcontent[date][i]['bannerimg'] + "' />";