c++ - 下面的代码报出bad allocation错误,求教为什么?
怪我咯
怪我咯 2017-04-17 10:59:13
[C++讨论组]

下面的代码报出bad allocation错误,求教为什么?

#include
#include
using namespace std;

class Student
{
public:
    Student();
    Student(int,string,float);//构造函数不能声明为虚函数,,,一般析构函数都声明都虚函数
    //在声明构造函数时,在最左边加virtual,声明为虚函数,用同一种方式调用同一类族中不同类的所有的同名函数。当基类的一个成员函数声明为虚函数时,默认其派生类中的同名函数自动成为虚函数
    virtual void display();
protected:
    int num;
    string name;
    float score;
};

Student::Student():num(0),name("NULL"),score(0){}
Student::Student(int n,string nam,float sco):num(n),name(nam),score(sco){
    cout<<"this is Student constructor."<display();
    pt=&grad1;
    pt->display();
    grad1.display();

    try{
        Doctor doc1(3,"lili",97.3,2090,20);//此处报错!!
        pt=&doc1;
        pt->display();
        doc1.display();
    }catch(std::exception const &ex)
    {
        cout<
                            
                                    
怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(1)
迷茫

下次能仔细点嘛!

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号