weixin_38008621 2017-09-27 07:19 采纳率: 0%
浏览 585

c++指针类的问题, bounds of current fuction以及其它问题,谢谢

运行的时候会崩溃,然后我调试的时候有出现cannot find bounds of current fuction,会出现截图的那种情况,貌似栈中指针找不到函数

源码
#include
#include

using namespace std;

class linklist
{
private:
struct node {
int data;
node *prev,*next;

node():prev(NULL),next(NULL){}    //初始化
~node(){}

};

node *head,*tail;    //头和尾指针
int currentlength;   //表长

public:
linklist(); //构造函数
~linklist() {clear(); delete head; delete tail;} //析构函数

void clear();  //清除各结点的函数
void show();
void setup();
linklist operator+(const linklist &r1) const ;

};

linklist::linklist()
{
head=new node;
head->next=tail=new node;
tail->prev=head;
currentlength=0;
}

void linklist::setup()
{
int x;
int i=0;
cout<<"请输入位数小于1000000的数"< cin>>x;
node *p,*q;

head=p=new node;
while(x<1000000){
    if(x==0) break;
    q=new node;
    ++i;
    q->data=x%int (pow(10,i));
    x=int (x/pow(10,i));
    p->next=q;
    q->prev=p;
    p=q;
    }
    p->next=tail;
    tail->prev=p;
    tail->next=NULL;
    head->prev=NULL;

    currentlength=i;

}

void linklist::clear()
{
node *p,*q;
p=head->next;
head->next=tail;
tail->prev=head;
while(p!=tail){
q=p->next;
delete p;
p=q;
}

currentlength=0;

}

void linklist::show()
{
node *q;
q=tail->prev;
while(q!=head){
cout<data;
q=q->prev;
}
}

linklist linklist::operator+(const linklist &r1) const
{
linklist tmp;
node *p,*p1,*p2,*q;

tmp.head=p=new node;
p1=r1.head->next;
p2=head->next;
int carry=0;
while(1){
    q=new node;

    if((p1->data+p2->data)>=10) {q->data=(carry+p1->data+p2->data-10); carry=1; }
    else {q->data=carry+p1->data+p2->data; carry=0;}

    if((p1->data+p2->data+carry)==0) break;

    p1=p1->next;
    p2=p2->next;
    p->next=q;
    q->prev=p;
    p=q;
    }

    p->next=tmp.tail;
    tail->prev=p;
    tail->next=NULL;
    head->prev=NULL;

    return tmp;

}

int main()
{
linklist number1,number2,number3;

number1.setup();
number2.setup();
number3=number1+number2;
number3.show();

return 0;
}图片说明

  • 写回答

3条回答 默认 最新

  • 晓·飞段 2017-09-27 07:29
    关注

    linklist number1 = new linklist();
    不用创建对象然后调用方法吗,

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP