| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 470 人关注过本帖
标题:新手求教,绝对不是作业贴,我们还没学c++呢。
取消只看楼主 加入收藏
Ooh_no
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-9-25
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
新手求教,绝对不是作业贴,我们还没学c++呢。
最近刚刚自己学了C++,于是就想练练手,写了一个链表的类,编译的时候都还没问题,但是运行的时候总出错。我用的是visual studio2008,代码如下:
#include<iostream>
#include<windows.h>
#include<stdlib.h>
using namespace std;

struct Node{struct Node *next;int data;};
class A
{
public:
    A();
    ~A();
    int push(int e);
    int pop();
    //bool erease();
    struct Node * begin();
    struct Node * end();
private:
    struct Node * V;
};
A::A()
{
    struct Node *H=new struct Node;
    H->next=NULL;
    (this->V)->next=H;
}
A::~A()
{
    delete [](this->V);
}
int A::push(int e)
{
    struct Node *B=new struct Node;
    struct Node *p;
    p=end();
    B->data= e;
    B->next= NULL;
    p->next=B;
    return 0;
}
/*int A::pop()
{
    struct Node *p,*q;
    p=end();
    q=begin();
    while(q->next != p)
        q=q->next;
    q->next=NULL;
    return p->data;
    delete p;
}
/*bool A::erease(struct Node *p)
{
    struct Node *q;
    while(q->next != p)
        q=q->next;
    q->next=p->next;
    delete p->next;
    return true;
}*/
struct Node *A::begin()
{
    return V->next;
}
struct Node *A::end()
{
    struct Node* p;
    p=begin();
    while(p->next != NULL)
        p=p->next;
    return p;
}
int main()
{
    int e,f=0;
    A shiyan;
    cin>>e;
    shiyan.push(e);
    //f=shiyan.pop();
    //cout<<f<<endl;
    system("pause");
    return 0;
}
在运行的时候,出现了错误提示:实验.exe 中的 0x00e71e2d 处未处理的异常: 0xC0000005: 写入位置 0xcccccccc 时发生访问冲突。
这个程序我看了几天了,还是找不出问题。这个到底是什么情况?望高手解答,谢谢了。

搜索更多相关主题的帖子: 作业 
2010-09-25 18:31
Ooh_no
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-9-25
收藏
得分:0 
呃 ,其实我其实就是想写个整数栈来着··
2010-09-25 21:20
Ooh_no
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-9-25
收藏
得分:0 
谢谢了
2010-09-26 16:07
快速回复:新手求教,绝对不是作业贴,我们还没学c++呢。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011590 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved