标题:代码出错了,能运行但是最后跳出个警告
取消只看楼主
黄昏乐章
Rank: 2
来 自:青岛
等 级:论坛游民
帖 子:73
专家分:25
注 册:2011-6-6
结帖率:88.89%
 问题点数:0 回复次数:3 
代码出错了,能运行但是最后跳出个警告
程序代码:
#include<iostream>
#include<cassert>
using namespace std;
class point{
public:
    point(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy;

    }
    point(point &a);
    int getX(){
        return x;
    }
    int getY()
    {
        return y;

    }
    void move(int newX, int newY){
        x = newX;
        y = newY;
        cout << getX() << "," << getY() << endl;
    }
private:
    int x, y;
};
class arrayofpoints{
public:
    arrayofpoints(int size) : sizes(size){
        points = new point[size];
    }
    ~arrayofpoints(){
        cout << "deleteing..." << endl;
        delete[] points;
    }
    point& element(){

        return *(points++);//一改这里能运行但是最后说了句debug assertion failed! 我输入了3或者4 
    }
private:
    point *points;
    int sizes;
};
int main()
{
    int count;
    cout << "please enter the count of points: ";
    cin >> count;
    arrayofpoints Points(count);
    
    Points.element().move(12, 56);
    Points.element().move(5, 0);
    return 0;
}

在书里扒了了代码自己改改
2015-07-23 17:06
黄昏乐章
Rank: 2
来 自:青岛
等 级:论坛游民
帖 子:73
专家分:25
注 册:2011-6-6
得分:0 
求大神指点
2015-07-23 17:15
黄昏乐章
Rank: 2
来 自:青岛
等 级:论坛游民
帖 子:73
专家分:25
注 册:2011-6-6
得分:0 
我个人认为是指针溢出但是不应该啊
2015-07-23 17:16
黄昏乐章
Rank: 2
来 自:青岛
等 级:论坛游民
帖 子:73
专家分:25
注 册:2011-6-6
得分:0 
回复 4楼 yangfrancis
正常编译,但是运行结束时出现wenti
2015-07-23 17:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-455696-1-1.html




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

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